org.restlet.engine.connector
Class InboundWay

java.lang.Object
  extended by org.restlet.engine.connector.Way
      extended by org.restlet.engine.connector.InboundWay
All Implemented Interfaces:
BufferProcessor, CompletionListener, SelectionListener
Direct Known Subclasses:
ClientInboundWay, ServerInboundWay

public abstract class InboundWay
extends Way

A network connection way though which messages are received. Messages can be either requests or responses.

Author:
Jerome Louvel

Constructor Summary
InboundWay(Connection<?> connection, int bufferSize)
          Constructor.
 
Method Summary
 void clear()
          Recycles the way so it can be reused.
protected  Representation createEntity(Series<Header> headers)
          Returns the message entity if available.
protected  boolean fillLine()
          Read the current message line (start line or header line).
protected  int getBuilderIndex()
          Returns the line builder index.
protected  SelectionRegistration getEntityRegistration()
          Returns the NIO selection registration of the entity.
 int getInterestOperations()
          Returns the operations of interest.
protected  boolean isLineReadable()
          Indicates if the next message line is readable.
 int onDrain(Buffer buffer, int maxDrained, Object... args)
          Drains the byte buffer by writing available bytes to the socket channel.
 void onError(Status status)
          Called on error.
 int onFill(Buffer buffer, Object... args)
          Fills the byte buffer by writing the current message.
 void onFillEof()
          Called back when a fill operation returns with an EOF status.
protected  void onHeadersCompleted()
          Callback invoked when a message has been received.
 void onMessageCompleted(boolean endDetected)
          Callback method invoked when the current message has been completely received or sent.
protected  void onPostProcessing()
          Called back after the IO processing to indicate if there is further IO interest.
protected abstract  void onReceived(Response message)
          Call back invoked when the message is received.
 void onTimeOut()
          Called back by the controller when an IO time out has been detected.
 int processIoBuffer()
          Processes the IO buffer by filling and draining it.
protected  Header readHeader()
          Read a message header.
protected abstract  void readStartLine()
          Read the start line of the current message received.
protected  void setBuilderIndex(int builderIndex)
          Sets the line builder index.
protected  void setEntityRegistration(SelectionRegistration entityRegistration)
          Sets the NIO selection registration of the entity.
 void updateState()
          Updates the way IO and message states.
 
Methods inherited from class org.restlet.engine.connector.Way
canLoop, clearLineBuilder, couldDrain, couldFill, getActualMessage, getBuffer, getConnection, getHeaders, getHelper, getIoState, getLineBuilder, getLineBuilderState, getLoadScore, getLogger, getMessage, getMessageState, getRegistration, hasIoInterest, isAvailable, isEmpty, onClosed, onSelected, postProcess, preProcess, setHeaders, setIoState, setLineBuilderState, setMessage, setMessageState, setRegistration, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InboundWay

public InboundWay(Connection<?> connection,
                  int bufferSize)
Constructor.

Parameters:
connection - The parent connection.
bufferSize - The byte buffer size.
Method Detail

clear

public void clear()
Description copied from class: Way
Recycles the way so it can be reused. Typically invoked by a connection pool.

Overrides:
clear in class Way

createEntity

protected Representation createEntity(Series<Header> headers)
Returns the message entity if available.

Parameters:
headers - The headers to use.
Returns:
The inbound message if available.

fillLine

protected boolean fillLine()
                    throws IOException
Read the current message line (start line or header line).

Returns:
True if the line is ready for reading.
Throws:
IOException

getBuilderIndex

protected int getBuilderIndex()
Returns the line builder index.

Returns:
The line builder index.

getEntityRegistration

protected SelectionRegistration getEntityRegistration()
Returns the NIO selection registration of the entity.

Returns:
The NIO selection registration of the entity.

getInterestOperations

public int getInterestOperations()
Description copied from class: Way
Returns the operations of interest.

Specified by:
getInterestOperations in class Way
Returns:
The operations of interest.

isLineReadable

protected boolean isLineReadable()
                          throws IOException
Indicates if the next message line is readable.

Returns:
True if the next message line is readable.
Throws:
IOException

onMessageCompleted

public void onMessageCompleted(boolean endDetected)
                        throws IOException
Description copied from class: Way
Callback method invoked when the current message has been completely received or sent.

Specified by:
onMessageCompleted in interface CompletionListener
Overrides:
onMessageCompleted in class Way
Parameters:
endDetected - Indicates if the end of the socket channel was detected.
Throws:
IOException

onDrain

public int onDrain(Buffer buffer,
                   int maxDrained,
                   Object... args)
            throws IOException
Description copied from class: Way
Drains the byte buffer by writing available bytes to the socket channel.

Specified by:
onDrain in interface BufferProcessor
Specified by:
onDrain in class Way
Parameters:
buffer - The IO buffer to drain.
maxDrained - The maximum number of bytes drained by this call.
args - The optional arguments to pass back to the callbacks.
Returns:
The number of bytes drained.
Throws:
IOException

onError

public void onError(Status status)
Description copied from class: Way
Called on error.

Specified by:
onError in class Way
Parameters:
status - The error status.

onFill

public int onFill(Buffer buffer,
                  Object... args)
           throws IOException
Description copied from class: Way
Fills the byte buffer by writing the current message.

Specified by:
onFill in interface BufferProcessor
Specified by:
onFill in class Way
Parameters:
buffer - The IO buffer to drain.
args - The optional arguments to pass back to the callbacks.
Returns:
The number of bytes filled.
Throws:
IOException

onFillEof

public void onFillEof()
Called back when a fill operation returns with an EOF status.


onPostProcessing

protected void onPostProcessing()
Description copied from class: Way
Called back after the IO processing to indicate if there is further IO interest. By default, it sets the IO state to IoState.INTEREST.

Specified by:
onPostProcessing in class Way

onHeadersCompleted

protected void onHeadersCompleted()
                           throws IOException
Callback invoked when a message has been received. Note that only the start line and the headers must have been received, not the optional body.

Specified by:
onHeadersCompleted in class Way
Throws:
IOException

onReceived

protected abstract void onReceived(Response message)
                            throws IOException
Call back invoked when the message is received.

Parameters:
message - The new message received.
Throws:
IOException

onTimeOut

public void onTimeOut()
Description copied from class: Way
Called back by the controller when an IO time out has been detected.

Specified by:
onTimeOut in class Way

processIoBuffer

public int processIoBuffer()
                    throws IOException
Description copied from class: Way
Processes the IO buffer by filling and draining it.

Overrides:
processIoBuffer in class Way
Throws:
IOException

readHeader

protected Header readHeader()
                     throws IOException
Read a message header.

Returns:
The new message header or null.
Throws:
IOException

readStartLine

protected abstract void readStartLine()
                               throws IOException
Read the start line of the current message received.

Throws:
IOException

setBuilderIndex

protected void setBuilderIndex(int builderIndex)
Sets the line builder index.

Parameters:
builderIndex - The line builder index.

setEntityRegistration

protected void setEntityRegistration(SelectionRegistration entityRegistration)
Sets the NIO selection registration of the entity.

Parameters:
entityRegistration - The NIO selection registration of the entity.

updateState

public void updateState()
Description copied from class: Way
Updates the way IO and message states.

Overrides:
updateState in class Way


Copyright © 2005-2013 Restlet.