Fixed bug where initialization wasn't affecting the isClosed status of a message (not initialized meant that the buffer was null which indicated the message was closed before it had ever started being sent). Moved isInitialized into the MessageBuffer base class.

This commit is contained in:
wcrisman
2014-12-29 09:18:59 -08:00
parent 28e0787f94
commit b3648439e6
2 changed files with 12 additions and 8 deletions

View File

@@ -20,8 +20,6 @@ public class HttpMessageBuffer extends MessageBuffer {
private Response response = null; private Response response = null;
/** The content if there is any. */ /** The content if there is any. */
private IContent content = null; private IContent content = null;
/** Flag indicating if initialization is required. */
private boolean isInitialized = false;
/** /**
* HttpMessageBuffer constructor. * HttpMessageBuffer constructor.
* @param socketContext The socket context associated with this message buffer. * @param socketContext The socket context associated with this message buffer.
@@ -37,8 +35,8 @@ public Response getResponse() {return response;}
* @see com.foundation.web.server.WebServer.MessageBuffer#initialize() * @see com.foundation.web.server.WebServer.MessageBuffer#initialize()
*/ */
public boolean initialize() { public boolean initialize() {
if(!isInitialized) { if(!getIsInitialized()) {
isInitialized = true; super.initialize();
prepareResponse(response); prepareResponse(response);
}//if// }//if//

View File

@@ -14,6 +14,8 @@ class MessageBuffer {
private ByteBuffer buffer = null; private ByteBuffer buffer = null;
/** The ability to chain message buffers into a linked list. */ /** The ability to chain message buffers into a linked list. */
private MessageBuffer next = null; private MessageBuffer next = null;
/** Flag indicating if initialization is required. */
private boolean isInitialized = false;
/** /**
* MessageBuffer constructor. * MessageBuffer constructor.
* @param socketContext The socket context associated with this message buffer. * @param socketContext The socket context associated with this message buffer.
@@ -34,6 +36,8 @@ public MessageBuffer(AbstractSocketContext socketContext, ByteBuffer buffer) {
protected WebServer getWebServer() {return socketContext.getWebServer();} protected WebServer getWebServer() {return socketContext.getWebServer();}
/** Gets the socket context that this message buffer exists within. */ /** Gets the socket context that this message buffer exists within. */
protected AbstractSocketContext getSocketContext() {return socketContext;} protected AbstractSocketContext getSocketContext() {return socketContext;}
/** Gets the whether the buffer has been initialized yet. */
protected boolean getIsInitialized() {return isInitialized;}
/** /**
* Sets the actual underlying buffer for the message buffer. * Sets the actual underlying buffer for the message buffer.
* @param buffer * @param buffer
@@ -45,11 +49,12 @@ protected void setBuffer(ByteBuffer buffer) {
if(buffer != null && buffer.position() != 0) buffer.flip(); if(buffer != null && buffer.position() != 0) buffer.flip();
}//setBuffer()// }//setBuffer()//
/** /**
* Initializes the message buffer for use. * Initializes the message buffer for use. Subclasses may implement but must call this method to set the isInitialized flag.
* @return Whether initialization succeded. Intialization should be considered a success even if none is required or has already been performed. If it fails the caller should close the socket. * @return Whether initialization succeded. Intialization should be considered a success even if none is required or has already been performed. If it fails the caller should close the socket.
*/ */
public boolean initialize() { public boolean initialize() {
//Does nothing by default. Subclasses may implement.// isInitialized = true;
return true; return true;
}//initialize()// }//initialize()//
/** /**
@@ -57,13 +62,14 @@ public boolean initialize() {
* @return If the bytes have all been sent. * @return If the bytes have all been sent.
*/ */
public boolean isClosed() { public boolean isClosed() {
return buffer == null; return isInitialized && buffer == null;
}//isClosed()// }//isClosed()//
/** /**
* Closes the message buffer. * Closes the message buffer.
*/ */
public void close() { public void close() {
this.buffer = null; buffer = null;
isInitialized = true;
}//close()// }//close()//
/** /**
* Gets the byte buffer containing the current portion of the message to be sent. * Gets the byte buffer containing the current portion of the message to be sent.