public abstract class OutboundWay extends Way
Constructor and Description |
---|
OutboundWay(Connection<?> connection,
int bufferSize)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addEntityHeaders(Representation entity,
Series<Header> headers)
Adds the entity headers for the given response.
|
protected void |
addGeneralHeaders(Series<Header> headers)
|
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.
|
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
public OutboundWay(Connection<?> connection, int bufferSize)
connection
- The parent connection.bufferSize
- The byte buffer size.protected static String getVersion(Request request)
request
- The request.protected void addEntityHeaders(Representation entity, Series<Header> headers)
entity
- The entity to inspect.protected void addGeneralHeaders(Series<Header> headers)
headers
- The target headers Series
.protected abstract void addHeaders(Series<Header> headers)
headers
- The headers to update.public void clear()
Way
public ReadableByteChannel getEntityChannel()
protected EntityType getEntityChannelType()
public FileChannel getEntityFileChannel()
public int getEntityInterestOps()
public SelectableChannel getEntitySelectableChannel()
public SelectionKey getEntitySelectionKey()
protected int getHeaderIndex()
public int getInterestOperations()
Way
getInterestOperations
in class Way
protected abstract void handle(Response response)
response
- protected boolean hasIoInterest()
Way
hasIoInterest
in class Way
public void onHeadersCompleted() throws IOException
onHeadersCompleted
in class Way
IOException
public void onMessageCompleted(boolean endReached) throws IOException
Way
onMessageCompleted
in interface CompletionListener
onMessageCompleted
in class Way
endReached
- Indicates if the end of the socket channel was detected.IOException
public int onDrain(Buffer buffer, int maxDrained, Object... args) throws IOException
Way
onDrain
in interface BufferProcessor
onDrain
in class Way
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.IOException
public int onFill(Buffer buffer, Object... args) throws IOException
Way
onFill
in interface BufferProcessor
onFill
in class Way
buffer
- The IO buffer to drain.args
- The optional arguments to pass back to the callbacks.IOException
public void onFillEof()
protected void onPostProcessing()
Way
IoState.INTEREST
.onPostProcessing
in class Way
public void onTimeOut()
Way
public int processIoBuffer() throws IOException
Way
processIoBuffer
in class Way
IOException
public void setEntityChannel(ReadableByteChannel entityChannel)
entityChannel
- The entity as a NIO readable byte channel.protected void setEntityChannelType(EntityType entityChannelType)
entityChannelType
- The type of the entity channel.public void setEntitySelectionKey(SelectionKey entityKey)
entityKey
- The entity's NIO selection key.protected void setHeaderIndex(int headerIndex)
headerIndex
- The header index.protected boolean shouldBeChunked(Representation entity)
entity
- The entity to analyze.public void updateState()
Way
updateState
in class Way
protected void writeLine() throws IOException
IOException
protected abstract void writeStartLine() throws IOException
IOException
public void flushBuffer()
Copyright © 2005–2014. All rights reserved.