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
public abstract class NetworkLayer extends Object implements ProtocolLayer, ProtocolLayer.Send
The lowestProtocolLayer
in aProtocolStack
. 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 Constructor Description NetworkLayer(IOHub ioHub)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected ByteBuffer
acquire()
SPI: Acquired a newByteBuffer
optimally sized for network read/write operations.abstract void
doCloseRecv()
Request the recv side to be closed.void
doSend(ByteBuffer data)
Sends data to the lower layer.IOHub
getIoHub()
Gets theIOHub
that we are using.void
init(ProtocolStack.Ptr ptr)
Initializes the layer with itsProtocolStack.Ptr
.protected boolean
isRecvOpen()
SPI: Check if the recipient is open.protected ByteBufferQueue
newByteBufferQueue()
SPI: Creates a newByteBuffer
optimally sized for network read/write operations.protected void
onRead(ByteBuffer data)
SPI: Performed the handling of te actual read from the recipient.protected void
onRecvClosed()
SPI: Notify that the connection with the recipient is closed.protected void
release(ByteBuffer buffer)
SPI: Returns a previously acquiredByteBuffer
to the pool.protected ProtocolStack<?>
stack()
Returns theProtocolStack
instance that we belong to.void
start()
Starts this layer.protected abstract void
write(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, wait
-
Methods inherited from interface org.jenkinsci.remoting.protocol.ProtocolLayer.Send
doCloseSend, isSendOpen
-
-
-
-
Method Detail
-
doSend
public final void doSend(@NonNull ByteBuffer data) throws IOException
Sends data to the lower layer.- Specified by:
doSend
in interfaceProtocolLayer.Send
- Parameters:
data
- the data to send. 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 there was an error during processing of the data.
-
write
protected abstract void write(@NonNull ByteBuffer data) throws IOException
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 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
-
onRead
protected final void onRead(ByteBuffer data) throws IOException
SPI: Performed the handling of te actual read from the recipient.- 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
-
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:
true
if the recipient is open.
-
init
public final void init(@NonNull ProtocolStack.Ptr ptr) throws IOException
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:
init
in interfaceProtocolLayer
- Parameters:
ptr
- the position of this layer in the stack.- Throws:
IOException
- if something goes wrong.
-
start
@OverrideMustInvoke public void start() throws IOException
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
- Throws:
IOException
- if something goes wrong.
-
getIoHub
@NonNull public IOHub getIoHub()
Gets theIOHub
that we are using.- Returns:
- the
IOHub
that we are using.
-
acquire
protected ByteBuffer acquire()
SPI: Acquired a newByteBuffer
optimally sized for network read/write operations.- Returns:
- a new
ByteBuffer
.
-
release
protected void release(ByteBuffer buffer)
SPI: Returns a previously acquiredByteBuffer
to the pool.- Parameters:
buffer
- theByteBuffer
.
-
newByteBufferQueue
protected ByteBufferQueue newByteBufferQueue()
SPI: Creates a newByteBuffer
optimally sized for network read/write operations.- Returns:
- a new
ByteBuffer
optimally sized for network read/write operations.
-
stack
protected ProtocolStack<?> stack()
Returns theProtocolStack
instance that we belong to.- Returns:
- the
ProtocolStack
instance that we belong to.
-
-