public class NIONetworkLayer extends NetworkLayer implements IOHubReadyListener
ProtocolLayer.Recv, ProtocolLayer.SendEMPTY_BUFFER, UTF_8| Constructor and Description |
|---|
NIONetworkLayer(IOHub ioHub,
ReadableByteChannel in,
WritableByteChannel out)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
doCloseRecv()
Request the recv side to be closed.
|
void |
doCloseSend()
Notify the lower layer that it should close.
|
boolean |
isSendOpen()
Tracks if this layer is submitting data to be sent via
ProtocolLayer.Send.doSend(ByteBuffer). |
void |
ready(boolean accept,
boolean connect,
boolean read,
boolean write)
Callback to indicate the
SelectableChannel that this listener was registered for is ready for the
indicated operations. |
void |
start()
Starts this layer.
|
protected void |
write(ByteBuffer data)
SPI: Perform the actual write to the recipient.
|
acquire, doSend, getIoHub, init, isRecvOpen, newByteBufferQueue, onRead, onRecvClosed, release, stackpublic NIONetworkLayer(IOHub ioHub, ReadableByteChannel in, WritableByteChannel out)
ioHub - our hub.in - the source of data.out - the sink for data.public void ready(boolean accept,
boolean connect,
boolean read,
boolean write)
SelectableChannel that this listener was registered for is ready for the
indicated operations. The SelectionKey.interestOps() will have been cleared for all the operations
that are true so the callback can be assured that processing of any one specific operation will
be linearized, though there may be concurrent calls to IOHubReadyListener.ready(boolean, boolean, boolean, boolean) with
disjoint ready operations. The callback will most likely want to re-register for
IOHub.addInterestRead(SelectionKey) or IOHub.addInterestAccept(SelectionKey) immediately before
returning from a ready notification of the read or accept status. The callback will only want to re-register
for a IOHub.addInterestWrite(SelectionKey) if it has filled the SelectableChannel's output
buffer and has more data to write.ready in interface IOHubReadyListeneraccept - if the SelectableChannel has a connection to accept. Call
IOHub.addInterestAccept(SelectionKey) to request additional callbacks for this ready
state.connect - if the SelectableChannel has established a connection. Call
IOHub.addInterestConnect(SelectionKey) to request additional callbacks for this ready
state.read - if the SelectableChannel has data available to read. Call
IOHub.addInterestRead(SelectionKey) to request additional callbacks for this ready state.write - if the SelectableChannel can accept data for writing. Call
IOHub.addInterestWrite(SelectionKey) to request additional callbacks for this ready state.protected void write(@Nonnull ByteBuffer data) throws IOException
NetworkLayer.write(ByteBuffer).write in class NetworkLayerdata - the data received. Any data consumed from the ByteBuffer can be assumed as processed.
Any data not consumed from the ByteBuffer will be the responsibility of the caller
to resubmit in subsequent calls.IOException - if something goes wrongpublic void doCloseRecv()
doCloseRecv in class NetworkLayerpublic void start()
throws IOException
start in interface ProtocolLayerstart in class NetworkLayerIOException - if something goes wrong.public void doCloseSend()
throws IOException
ProtocolLayer.Recv.onRecvClosed(IOException) for any upper layers.doCloseSend in interface ProtocolLayer.SendIOException - if there was an error closing the lower layer.public boolean isSendOpen()
ProtocolLayer.Send.doSend(ByteBuffer).
Once this method returns false it must always return false and can be assumed to behave in
this way.isSendOpen in interface ProtocolLayer.Sendtrue if submitting data to be sent via ProtocolLayer.Send.doSend(ByteBuffer).Copyright © 2004–2018. All rights reserved.