public abstract class Way extends Object implements SelectionListener, CompletionListener, BufferProcessor
Constructor and Description |
---|
Way(Connection<?> connection,
int bufferSize)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canLoop(Buffer buffer,
Object... args)
Indicates if the processing loop can continue.
|
void |
clear()
Recycles the way so it can be reused.
|
protected void |
clearLineBuilder()
Clears the line builder and adjust its state.
|
boolean |
couldDrain(Buffer buffer,
Object... args)
Indicates if the buffer could be drained again.
|
boolean |
couldFill(Buffer buffer,
Object... args)
Indicates if the buffer could be filled again.
|
abstract Message |
getActualMessage()
Returns the actual message, request or response.
|
Buffer |
getBuffer()
Returns the IO buffer.
|
Connection<?> |
getConnection()
Returns the parent connection.
|
Series<Header> |
getHeaders()
Returns the response headers.
|
ConnectionHelper<?> |
getHelper()
Returns the parent connector helper.
|
abstract int |
getInterestOperations()
Returns the operations of interest.
|
IoState |
getIoState()
Returns the IO state.
|
StringBuilder |
getLineBuilder()
Returns the line builder.
|
BufferState |
getLineBuilderState()
Returns the line builder state.
|
int |
getLoadScore()
Returns a score representing the way load and that could be compared with
other ways of the same parent connection.
|
protected Logger |
getLogger()
Returns the logger.
|
Response |
getMessage()
Returns the current message processed.
|
MessageState |
getMessageState()
Returns the message state.
|
SelectionRegistration |
getRegistration()
Returns the socket's NIO registration holding the link between the
channel and the connection.
|
protected boolean |
hasIoInterest()
Indicates if we want to be selected for IO processing when the socket
related socket is prepared.
|
boolean |
isAvailable()
Indicates if the way is available to handle new messages.
|
boolean |
isEmpty()
Indicates if the way is empty.
|
void |
onClosed()
Callback method invoked when the parent connection is ready to be closed.
|
abstract int |
onDrain(Buffer buffer,
int maxDrained,
Object... args)
Drains the byte buffer by writing available bytes to the socket channel.
|
abstract void |
onError(Status status)
Called on error.
|
abstract int |
onFill(Buffer buffer,
Object... args)
Fills the byte buffer by writing the current message.
|
protected abstract void |
onHeadersCompleted()
Callback method invoked when the headers of the current message have been
completely received or sent.
|
void |
onMessageCompleted(boolean endDetected)
Callback method invoked when the current message has been completely
received or sent.
|
protected abstract void |
onPostProcessing()
Called back after the IO processing to indicate if there is further IO
interest.
|
void |
onSelected(SelectionRegistration selectionRegistration)
Callback method invoked when the way has been selected for IO operations
it registered interest in.
|
abstract void |
onTimeOut()
Called back by the controller when an IO time out has been detected.
|
void |
postProcess(int drained)
Does nothing by default.
|
int |
preProcess(int maxDrained,
Object... args)
Does nothing by default.
|
protected int |
processIoBuffer()
Processes the IO buffer by filling and draining it.
|
protected void |
setHeaders(Series<Header> headers)
Sets the response headers to be written.
|
void |
setIoState(IoState ioState)
Sets the IO state.
|
protected void |
setLineBuilderState(BufferState lineBuilderState)
Sets the line builder state.
|
protected void |
setMessage(Response message)
Sets the current message processed.
|
protected void |
setMessageState(MessageState messageState)
Sets the message state.
|
protected void |
setRegistration(SelectionRegistration registration)
Sets the NIO selection registration holding the link between the
connection and the way.
|
String |
toString() |
void |
updateState()
Updates the way IO and message states.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
onFillEof
public Way(Connection<?> connection, int bufferSize)
connection
- The parent connection.bufferSize
- The byte buffer size.public boolean canLoop(Buffer buffer, Object... args)
canLoop
in interface BufferProcessor
buffer
- The IO buffer to drain.args
- The optional arguments to pass back to the callbacks.public void clear()
protected void clearLineBuilder()
public boolean couldDrain(Buffer buffer, Object... args)
buffer
- The IO buffer to drain.args
- The optional arguments to pass back to the callbacks.public boolean couldFill(Buffer buffer, Object... args)
couldFill
in interface BufferProcessor
buffer
- The IO buffer to fill.args
- The optional arguments to pass back to the callbacks.public abstract Message getActualMessage()
public Buffer getBuffer()
public Connection<?> getConnection()
public Series<Header> getHeaders()
public ConnectionHelper<?> getHelper()
public abstract int getInterestOperations()
public IoState getIoState()
public StringBuilder getLineBuilder()
public BufferState getLineBuilderState()
public int getLoadScore()
protected Logger getLogger()
public Response getMessage()
public MessageState getMessageState()
public SelectionRegistration getRegistration()
protected boolean hasIoInterest()
public boolean isAvailable()
public boolean isEmpty()
public void onClosed()
public abstract int onDrain(Buffer buffer, int maxDrained, Object... args) throws IOException
onDrain
in interface BufferProcessor
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 abstract void onError(Status status)
status
- The error status.public abstract int onFill(Buffer buffer, Object... args) throws IOException
onFill
in interface BufferProcessor
buffer
- The IO buffer to drain.args
- The optional arguments to pass back to the callbacks.IOException
protected abstract void onHeadersCompleted() throws IOException
IOException
public void onMessageCompleted(boolean endDetected) throws IOException
onMessageCompleted
in interface CompletionListener
endDetected
- Indicates if the end of the socket channel was detected.IOException
protected abstract void onPostProcessing()
IoState.INTEREST
.public void onSelected(SelectionRegistration selectionRegistration)
onSelected
in interface SelectionListener
selectionRegistration
- The selected registration.public abstract void onTimeOut()
public void postProcess(int drained) throws IOException
postProcess
in interface BufferProcessor
drained
- The number of bytes drained or -1 if the filling source has
ended.IOException
public int preProcess(int maxDrained, Object... args) throws IOException
preProcess
in interface BufferProcessor
maxDrained
- The maximum number of bytes drained by this call or 0 for
unlimited length.args
- The optional arguments to pass back to the callbacks.IOException
protected int processIoBuffer() throws IOException
IOException
protected void setHeaders(Series<Header> headers)
headers
- The response headers.public void setIoState(IoState ioState)
ioState
- The IO state.protected void setLineBuilderState(BufferState lineBuilderState)
lineBuilderState
- The line builder state.protected void setMessage(Response message)
message
- The current message processed.protected void setMessageState(MessageState messageState)
messageState
- The message state.protected void setRegistration(SelectionRegistration registration)
registration
- The NIO selection registration holding the link between the
connection and the way.public void updateState()
Copyright © 2005–2019. All rights reserved.