Fields Summary |
---|
protected static boolean | embeddedInGlassFishIs Grizzly embedded in GlassFish. |
private int | port |
protected int | contentLengthThe actual length of the stream we are able to read. |
protected int | curLimitThe ByteBuffer current limit value |
protected int | curPositionThe ByteBuffer current position value |
protected int | headerLengthThe position, within the ByteBuffer , when the HTTP
headers are completely reads. |
protected int | lastStatePositionIn case we were'nt able to parse the request line, we will continue
parsing from that position. |
protected int | stateIf the stream wasn't read fully, keep the state of the http parsing. |
protected ByteBuffer | primaryByteBufferIf a new ByteBuffer is created because the stream is
too small, cache the original byteBuffer and reuse it once the
transaction has completed. |
protected boolean | useByteBufferViewIf true , use a ByteBuffer view instead of
ByteBuffer |
protected boolean | useDirectByteBufferAre we using direct ByteBuffer |
protected SocketChannel | socketChannelThe SocketChannel associated with this algorithm. |
protected com.sun.enterprise.web.connector.grizzly.Handler | handlerAn Handler implementation used to implement a
static resources cache. |
Methods Summary |
---|
public java.nio.ByteBuffer | allocate(boolean useDirectByteBuffer, boolean useByteBufferView, int size)Allocate a ByteBuffer
ByteBuffer byteBuffer;
if (useByteBufferView){
byteBuffer = ByteBufferFactory.allocateView(size,
useDirectByteBuffer);
} else if ( useDirectByteBuffer ){
byteBuffer = ByteBuffer.allocateDirect(size);
} else {
byteBuffer = ByteBuffer.allocate(size);
}
return byteBuffer;
|
public int | contentLength()Return the stream content-length. If the content-length wasn't parsed,
return -1.
return contentLength;
|
protected java.lang.String | dump(java.nio.ByteBuffer byteBuffer)Dump the ByteBuffer content. This is used only for debugging purpose.
ByteBuffer dd = byteBuffer.duplicate();
dd.flip();
int length = dd.limit();
byte[] dump = new byte[length];
dd.get(dump,0,length);
return(new String(dump) + "\n----------------------------" + dd
+ "\ncontentLength: " + contentLength
+ "\nheaderLength: " + headerLength);
|
public int | getPort()Return the port
return port;
|
public java.lang.Class | getReadTask(com.sun.enterprise.web.connector.grizzly.SelectorThread selectorThread)Return the full name of the class responsible for handling OP_READ.
if ( selectorThread.getMaxReadWorkerThreads() <= 0
&& !selectorThread.getEnableAsyncExecution())
return com.sun.enterprise.web.connector.grizzly.DefaultReadTask.class;
else
return com.sun.enterprise.web.connector.grizzly.AsyncReadTask.class;
|
public int | headerLength()Return the stream header length. The header length is the length between
the start of the stream and the first occurance of character '\r\n' .
return headerLength;
|
public abstract boolean | parse(java.nio.ByteBuffer byteBuffer)Manipulate the bytes stream and determine if the process can continue.
|
public java.nio.ByteBuffer | postParse(java.nio.ByteBuffer byteBuffer)After parsing the bytes, post process the ByteBuffer
// Swap buffer to its original size.
if ( primaryByteBuffer != null) {
primaryByteBuffer.clear();
byteBuffer = primaryByteBuffer;
primaryByteBuffer = null;
}
return byteBuffer;
|
public java.nio.ByteBuffer | preParse(java.nio.ByteBuffer byteBuffer)Before parsing the bytes, initialize and prepare the algorithm.
if (byteBuffer.position() == byteBuffer.capacity()){
// Add space at the end for \n\r
int bufferSize = contentLength > 0 ?
contentLength + headerLength + 5:
byteBuffer.capacity() * 2;
byteBuffer = swapBuffer(byteBuffer,bufferSize);
}
return byteBuffer;
|
public void | recycle()Reset this object to its default state.
contentLength = -1;
lastStatePosition= -1;
headerLength = -1;
curLimit = -1;
curPosition = -1;
state = 0;
|
public java.nio.ByteBuffer | rollbackParseState(java.nio.ByteBuffer byteBuffer)Rollback the ByteBuffer to its previous state in case
an error as occured.
/**
* Set the <code>ByteBuffer</code> position/limit to the value
* they were before trying to process the stream.
*/
if (curLimit != -1 && curPosition != -1){
byteBuffer.limit(curLimit);
byteBuffer.position(curPosition);
// Reset so we can process a new request.
contentLength = -1;
headerLength = -1;
}
return byteBuffer;
|
public void | setPort(int port)Set the port
this.port = port;
|
public void | setSocketChannel(java.nio.channels.SocketChannel socketChannel)The SocketChannel used by this class.
this.socketChannel = socketChannel;
if ( socketChannel != null)
handler.attachChannel(socketChannel);
|
private java.nio.ByteBuffer | swapBuffer(java.nio.ByteBuffer byteBuffer, int size)Allocate a new ByteBuffer and put the content of the current
one into it.
ByteBuffer tmp = allocate(useDirectByteBuffer,useByteBufferView, size);
byteBuffer.flip();
tmp.put(byteBuffer);
// Keep a pointer to the original one.
if ( primaryByteBuffer == null) {
primaryByteBuffer = byteBuffer;
}
byteBuffer = tmp;
return byteBuffer;
|