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
ConstructorsConstructorDescriptionNIONetworkLayer(IOHub ioHub, ReadableByteChannel in, WritableByteChannel out) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidRequest the recv side to be closed.voidNotify the lower layer that it should close.booleanTracks if this layer is submitting data to be sent viaProtocolLayer.Send.doSend(ByteBuffer).voidready(boolean accept, boolean connect, boolean read, boolean write) Callback to indicate theSelectableChannelthat this listener was registered for is ready for the indicated operations.voidstart()Starts this layer.protected voidwrite(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 theSelectableChannelthat this listener was registered for is ready for the indicated operations. TheSelectionKey.interestOps()will have been cleared for all the operations that aretrueso 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:
readyin interfaceIOHubReadyListener- Parameters:
accept- if theSelectableChannelhas a connection to accept. CallIOHub.addInterestAccept(SelectionKey)to request additional callbacks for this ready state.connect- if theSelectableChannelhas established a connection. CallIOHub.addInterestConnect(SelectionKey)to request additional callbacks for this ready state.read- if theSelectableChannelhas data available to read. CallIOHub.addInterestRead(SelectionKey)to request additional callbacks for this ready state.write- if theSelectableChannelcan 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:
writein classNetworkLayer- Parameters:
data- the data received. Any data consumed from theByteBuffercan be assumed as processed. Any data not consumed from theByteBufferwill 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:
doCloseRecvin 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:
startin interfaceProtocolLayer- Overrides:
startin 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:
doCloseSendin interfaceProtocolLayer.Send
-
isSendOpen
public boolean isSendOpen()Tracks if this layer is submitting data to be sent viaProtocolLayer.Send.doSend(ByteBuffer). Once this method returnsfalseit must always returnfalseand can be assumed to behave in this way.- Specified by:
isSendOpenin interfaceProtocolLayer.Send- Returns:
trueif submitting data to be sent viaProtocolLayer.Send.doSend(ByteBuffer).
-