public class NIONetworkLayer extends NetworkLayer implements IOHubReadyListener
ProtocolLayer.Recv, ProtocolLayer.Send
EMPTY_BUFFER
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, stack
public 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 ready() 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 IOHubReadyListener
accept
- 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
write
in class NetworkLayer
data
- 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 NetworkLayer
public void start() throws IOException
start
in interface ProtocolLayer
start
in class NetworkLayer
IOException
- if something goes wrong.public void doCloseSend()
ProtocolLayer.Recv.onRecvClosed(IOException)
for any upper layers.doCloseSend
in interface ProtocolLayer.Send
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.Send
true
if submitting data to be sent via ProtocolLayer.Send.doSend(ByteBuffer)
.Copyright © 2004–2022. All rights reserved.