org.restlet.engine.connector
Class OutboundWay

java.lang.Object
  extended by org.restlet.engine.connector.Way
      extended by org.restlet.engine.connector.OutboundWay
All Implemented Interfaces:
BufferProcessor, CompletionListener, SelectionListener
Direct Known Subclasses:
ClientOutboundWay, ServerOutboundWay

public abstract class OutboundWay
extends Way

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

Author:
Jerome Louvel

Constructor Summary
OutboundWay(Connection<?> connection, int bufferSize)
          Constructor.
 
Method Summary
protected  void addEntityHeaders(Representation entity, Series<Header> headers)
          Adds the entity headers for the given response.
protected  void addGeneralHeaders(Series<Header> headers)
          Adds the general headers from the Message to the Series.
protected abstract  void addHeaders(Series<Header> headers)
          Add all the headers, including the general, the message specific and the entity headers.
 void clear()
          Recycles the way so it can be reused.
 void flushBuffer()
          Flush buffers onto the network.
 ReadableByteChannel getEntityChannel()
          Returns the entity as a NIO readable byte channel.
protected  EntityType getEntityChannelType()
          Returns the type of the entity channel.
 FileChannel getEntityFileChannel()
          Returns the entity as a NIO file channel.
 int getEntityInterestOps()
          Registers interest of this way for socket NIO operations.
 SelectableChannel getEntitySelectableChannel()
          Returns the entity as a NIO non-blocking selectable channel.
 SelectionKey getEntitySelectionKey()
          Returns the entity's NIO selection key holding the link between the entity to be written and the way.
protected  int getHeaderIndex()
          Returns the header index.
 int getInterestOperations()
          Returns the operations of interest.
protected static String getVersion(Request request)
          Returns the protocol version.
protected abstract  void handle(Response response)
          Add a message to the outbound way.
protected  boolean hasIoInterest()
          Indicates if we want to be selected for IO processing when the socket related socket is prepared.
 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.
 void onHeadersCompleted()
          Callback invoked when a message has been sent.
 void onMessageCompleted(boolean endReached)
          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.
 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.
 void setEntityChannel(ReadableByteChannel entityChannel)
          Sets the entity as a NIO readable byte channel.
protected  void setEntityChannelType(EntityType entityChannelType)
          Sets the type of the entity channel.
 void setEntitySelectionKey(SelectionKey entityKey)
          Sets the entity's NIO selection key holding the link between the entity to be written and the way.
protected  void setHeaderIndex(int headerIndex)
          Sets the header index.
protected  boolean shouldBeChunked(Representation entity)
          Indicates if the entity should be chunked because its length is unknown.
 void updateState()
          Updates the way IO and message states.
protected  void writeLine()
          Write a new line into the line builder.
protected abstract  void writeStartLine()
          Writes the start line of the current outbound message.
 
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, 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

OutboundWay

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

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

getVersion

protected static String getVersion(Request request)
Returns the protocol version.

Parameters:
request - The request.
Returns:
The protocol version.

addEntityHeaders

protected void addEntityHeaders(Representation entity,
                                Series<Header> headers)
Adds the entity headers for the given response.

Parameters:
entity - The entity to inspect.

addGeneralHeaders

protected void addGeneralHeaders(Series<Header> headers)
Adds the general headers from the Message to the Series.

Parameters:
headers - The target headers Series.

addHeaders

protected abstract void addHeaders(Series<Header> headers)
Add all the headers, including the general, the message specific and the entity headers.

Parameters:
headers - The headers to update.

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

getEntityChannel

public ReadableByteChannel getEntityChannel()
Returns the entity as a NIO readable byte channel.

Returns:
The entity as a NIO readable byte channel.

getEntityChannelType

protected EntityType getEntityChannelType()
Returns the type of the entity channel.

Returns:
The type of the entity channel.

getEntityFileChannel

public FileChannel getEntityFileChannel()
Returns the entity as a NIO file channel.

Returns:
The entity as a NIO file channel.

getEntityInterestOps

public int getEntityInterestOps()
Registers interest of this way for socket NIO operations.

Returns:
The operations of interest.

getEntitySelectableChannel

public SelectableChannel getEntitySelectableChannel()
Returns the entity as a NIO non-blocking selectable channel.

Returns:
The entity as a NIO non-blocking selectable channel.

getEntitySelectionKey

public SelectionKey getEntitySelectionKey()
Returns the entity's NIO selection key holding the link between the entity to be written and the way.

Returns:
The entity's NIO selection key.

getHeaderIndex

protected int getHeaderIndex()
Returns the header index.

Returns:
The header index.

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.

handle

protected abstract void handle(Response response)
Add a message to the outbound way.

Parameters:
response -

hasIoInterest

protected boolean hasIoInterest()
Description copied from class: Way
Indicates if we want to be selected for IO processing when the socket related socket is prepared.

Overrides:
hasIoInterest in class Way
Returns:
True if we want to be selected for IO processing when the socket is ready.

onHeadersCompleted

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

Specified by:
onHeadersCompleted in class Way
Throws:
IOException

onMessageCompleted

public void onMessageCompleted(boolean endReached)
                        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:
endReached - 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

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

setEntityChannel

public void setEntityChannel(ReadableByteChannel entityChannel)
Sets the entity as a NIO readable byte channel.

Parameters:
entityChannel - The entity as a NIO readable byte channel.

setEntityChannelType

protected void setEntityChannelType(EntityType entityChannelType)
Sets the type of the entity channel.

Parameters:
entityChannelType - The type of the entity channel.

setEntitySelectionKey

public void setEntitySelectionKey(SelectionKey entityKey)
Sets the entity's NIO selection key holding the link between the entity to be written and the way.

Parameters:
entityKey - The entity's NIO selection key.

setHeaderIndex

protected void setHeaderIndex(int headerIndex)
Sets the header index.

Parameters:
headerIndex - The header index.

shouldBeChunked

protected boolean shouldBeChunked(Representation entity)
Indicates if the entity should be chunked because its length is unknown.

Parameters:
entity - The entity to analyze.
Returns:
True if the entity should be chunked.

updateState

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

Overrides:
updateState in class Way

writeLine

protected void writeLine()
                  throws IOException
Write a new line into the line builder.

Throws:
IOException

writeStartLine

protected abstract void writeStartLine()
                                throws IOException
Writes the start line of the current outbound message.

Throws:
IOException

flushBuffer

public void flushBuffer()
Flush buffers onto the network.



Copyright © 2005-2013 Restlet.