Class NIONetworkLayer
java.lang.Object
org.jenkinsci.remoting.protocol.NetworkLayer
org.jenkinsci.remoting.protocol.impl.NIONetworkLayer
- All Implemented Interfaces:
IOHubReadyListener
,ProtocolLayer
,ProtocolLayer.Send
- Since:
- 3.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jenkinsci.remoting.protocol.ProtocolLayer
ProtocolLayer.Recv, ProtocolLayer.Send
-
Field Summary
Fields inherited from interface org.jenkinsci.remoting.protocol.ProtocolLayer
EMPTY_BUFFER
-
Constructor Summary
ConstructorDescriptionNIONetworkLayer
(IOHub ioHub, ReadableByteChannel in, WritableByteChannel out) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Request the recv side to be closed.void
Notify the lower layer that it should close.boolean
Tracks if this layer is submitting data to be sent viaProtocolLayer.Send.doSend(ByteBuffer)
.void
ready
(boolean accept, boolean connect, boolean read, boolean write) Callback to indicate theSelectableChannel
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.Methods inherited from class org.jenkinsci.remoting.protocol.NetworkLayer
acquire, doSend, getIoHub, init, isRecvOpen, newByteBufferQueue, onRead, onRecvClosed, release, stack
-
Constructor Details
-
NIONetworkLayer
Constructor.- Parameters:
ioHub
- our hub.in
- the source of data.out
- the sink for data.
-
-
Method Details
-
ready
public void ready(boolean accept, boolean connect, boolean read, boolean write) Callback to indicate theSelectableChannel
that this listener was registered for is ready for the indicated operations. TheSelectionKey.interestOps()
will have been cleared for all the operations that aretrue
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 forIOHub.addInterestRead(SelectionKey)
orIOHub.addInterestAccept(SelectionKey)
immediately before returning from a ready notification of the read or accept status. The callback will only want to re-register for aIOHub.addInterestWrite(SelectionKey)
if it has filled theSelectableChannel
's output buffer and has more data to write.- Specified by:
ready
in interfaceIOHubReadyListener
- Parameters:
accept
- if theSelectableChannel
has a connection to accept. CallIOHub.addInterestAccept(SelectionKey)
to request additional callbacks for this ready state.connect
- if theSelectableChannel
has established a connection. CallIOHub.addInterestConnect(SelectionKey)
to request additional callbacks for this ready state.read
- if theSelectableChannel
has data available to read. CallIOHub.addInterestRead(SelectionKey)
to request additional callbacks for this ready state.write
- if theSelectableChannel
can accept data for writing. CallIOHub.addInterestWrite(SelectionKey)
to request additional callbacks for this ready state.
-
write
SPI: Perform the actual write to the recipient. This method should be non-blocking. The data should be enqueued and written in the order of calls to write()}.- Specified by:
write
in classNetworkLayer
- Parameters:
data
- the data received. Any data consumed from theByteBuffer
can be assumed as processed. Any data not consumed from theByteBuffer
will be the responsibility of the caller to resubmit in subsequent calls.- Throws:
IOException
- if something goes wrong
-
doCloseRecv
public void doCloseRecv()Request the recv side to be closed.- Specified by:
doCloseRecv
in classNetworkLayer
-
start
Starts this layer. All layers in the stack will be initialized before a call to this method. All lower layers in the stack will have been started before this layer is started.- Specified by:
start
in interfaceProtocolLayer
- Overrides:
start
in classNetworkLayer
- Throws:
IOException
- if something goes wrong.
-
doCloseSend
public void doCloseSend()Notify the lower layer that it should close. Callers to this method are assumed to have already calledProtocolLayer.Recv.onRecvClosed(IOException)
for any upper layers.- Specified by:
doCloseSend
in interfaceProtocolLayer.Send
-
isSendOpen
public boolean isSendOpen()Tracks if this layer is submitting data to be sent viaProtocolLayer.Send.doSend(ByteBuffer)
. Once this method returnsfalse
it must always returnfalse
and can be assumed to behave in this way.- Specified by:
isSendOpen
in interfaceProtocolLayer.Send
- Returns:
true
if submitting data to be sent viaProtocolLayer.Send.doSend(ByteBuffer)
.
-