com.sun.enterprise.web.connector.grizzly
Interface StreamAlgorithm

All Known Implementing Classes:
ContentLengthAlgorithm, ContextRootAlgorithm, NoParsingAlgorithm, SeekHeaderAlgorithm, StateMachineAlgorithm, StaticStreamAlgorithm, StreamAlgorithmBase

public interface StreamAlgorithm

This interface defines the methods an instance of a ReadTask will invoke. The ReadTask will use an implementation of this interface tp predict if the NIO code>ByteBuffer has been fully read and can be processed. ReadTask will invoke the method in the following order: (a) allocate(...) (b) preParse(...) (c) parse(...) (d) contentLength() AND headerLength(); (d) postParse(...) The algorithm will stop once (c) return true

Author:
Jean-Francois Arcand

Method Summary
 ByteBuffer allocate(boolean useDirect, boolean useView, int size)
          Allocate a ByteBuffer
 int contentLength()
          Return the stream content-length.
 Handler getHandler()
          The Handler associated with this algorithm.
 int getPort()
          Return the port
 Class getReadTask(SelectorThread selectorThread)
          Return the class responsible for handling OP_READ.
 int headerLength()
          Return the stream header length.
 boolean parse(ByteBuffer byteBuffer)
          Parse the ByteBuffer and try to determine if the bytes stream has been fully read from the SocketChannel.
 ByteBuffer postParse(ByteBuffer byteBuffer)
          After parsing the bytes, post process the ByteBuffer
 ByteBuffer preParse(ByteBuffer byteBuffer)
          Before parsing the bytes, initialize and prepare the algorithm.
 void recycle()
          Recycle the algorithm.
 ByteBuffer rollbackParseState(ByteBuffer byteBuffer)
          Rollback the ByteBuffer to its previous state in case an error as occured.
 void setPort(int port)
          Set the port this algorithm is used.
 void setSocketChannel(SocketChannel socketChannel)
          Set the SocketChannel used by this algorithm
 

Method Detail

contentLength

int contentLength()
Return the stream content-length. If the content-length wasn't parsed, return -1.


headerLength

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' .


allocate

ByteBuffer allocate(boolean useDirect,
                    boolean useView,
                    int size)
Allocate a ByteBuffer

Parameters:
useDirect - allocate a direct ByteBuffer.
useView - allocate a view ByteBuffer.
size - the size of the newly created ByteBuffer.
Returns:
a new ByteBuffer

preParse

ByteBuffer preParse(ByteBuffer byteBuffer)
Before parsing the bytes, initialize and prepare the algorithm.

Parameters:
byteBuffer - the ByteBuffer used by this algorithm
Returns:
ByteBuffer used by this algorithm

parse

boolean parse(ByteBuffer byteBuffer)
Parse the ByteBuffer and try to determine if the bytes stream has been fully read from the SocketChannel.

Returns:
true if the algorithm determines the end of the stream.

postParse

ByteBuffer postParse(ByteBuffer byteBuffer)
After parsing the bytes, post process the ByteBuffer

Parameters:
byteBuffer - the ByteBuffer used by this algorithm
Returns:
ByteBuffer used by this algorithm

recycle

void recycle()
Recycle the algorithm.


rollbackParseState

ByteBuffer rollbackParseState(ByteBuffer byteBuffer)
Rollback the ByteBuffer to its previous state in case an error as occured.


getHandler

Handler getHandler()
The Handler associated with this algorithm.


setSocketChannel

void setSocketChannel(SocketChannel socketChannel)
Set the SocketChannel used by this algorithm


setPort

void setPort(int port)
Set the port this algorithm is used.


getPort

int getPort()
Return the port


getReadTask

Class getReadTask(SelectorThread selectorThread)
Return the class responsible for handling OP_READ.



Copyright © 2005-2015 Oracle Corporation. All Rights Reserved.