Package org.jenkinsci.remoting.protocol
Class NetworkLayer
java.lang.Object
org.jenkinsci.remoting.protocol.NetworkLayer
- All Implemented Interfaces:
ProtocolLayer,ProtocolLayer.Send
- Direct Known Subclasses:
BIONetworkLayer,NIONetworkLayer
The lowest
ProtocolLayer in a ProtocolStack. This layer is responsible for sending the output of
the protocol
to the recipient and injecting the input from the recipient into the protocol stack.- 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ByteBufferacquire()SPI: Acquired a newByteBufferoptimally sized for network read/write operations.abstract voidRequest the recv side to be closed.final voiddoSend(ByteBuffer data) Sends data to the lower layer.getIoHub()Gets theIOHubthat we are using.final voidinit(ProtocolStack<?>.Ptr ptr) Initializes the layer with itsProtocolStack.Ptr.protected final booleanSPI: Check if the recipient is open.protected ByteBufferQueueSPI: Creates a newByteBufferoptimally sized for network read/write operations.protected final voidonRead(ByteBuffer data) SPI: Performed the handling of te actual read from the recipient.protected final voidSPI: Notify that the connection with the recipient is closed.protected voidrelease(ByteBuffer buffer) SPI: Returns a previously acquiredByteBufferto the pool.protected ProtocolStack<?>stack()Returns theProtocolStackinstance that we belong to.voidstart()Starts this layer.protected abstract voidwrite(ByteBuffer data) SPI: Perform the actual write to the recipient.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jenkinsci.remoting.protocol.ProtocolLayer.Send
doCloseSend, isSendOpen
-
Constructor Details
-
NetworkLayer
Constructor.- Parameters:
ioHub- theIOHubthat we use.
-
-
Method Details
-
doSend
Sends data to the lower layer.- Specified by:
doSendin interfaceProtocolLayer.Send- Parameters:
data- the data to send. 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 there was an error during processing of the data.
-
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()}.- 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
-
onRead
SPI: Performed the handling of te actual read from the recipient.- 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
-
onRecvClosed
@OverrideMustInvoke protected final void onRecvClosed()SPI: Notify that the connection with the recipient is closed. -
doCloseRecv
public abstract void doCloseRecv()Request the recv side to be closed. -
isRecvOpen
protected final boolean isRecvOpen()SPI: Check if the recipient is open.- Returns:
trueif the recipient is open.
-
init
Initializes the layer with itsProtocolStack.Ptr. All lower layers in the stack will be initialized before a call to this method. All layers in a stack will be initialized before a call toProtocolLayer.start().- Specified by:
initin interfaceProtocolLayer- Parameters:
ptr- the position of this layer in the stack.- Throws:
IOException- if something goes wrong.
-
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- Throws:
IOException- if something goes wrong.
-
getIoHub
Gets theIOHubthat we are using.- Returns:
- the
IOHubthat we are using.
-
acquire
SPI: Acquired a newByteBufferoptimally sized for network read/write operations.- Returns:
- a new
ByteBuffer.
-
release
SPI: Returns a previously acquiredByteBufferto the pool.- Parameters:
buffer- theByteBuffer.
-
newByteBufferQueue
SPI: Creates a newByteBufferoptimally sized for network read/write operations.- Returns:
- a new
ByteBufferoptimally sized for network read/write operations.
-
stack
Returns theProtocolStackinstance that we belong to.- Returns:
- the
ProtocolStackinstance that we belong to.
-