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 ByteBuffer
acquire()
SPI: Acquired a newByteBuffer
optimally sized for network read/write operations.abstract void
Request the recv side to be closed.final void
doSend
(ByteBuffer data) Sends data to the lower layer.getIoHub()
Gets theIOHub
that we are using.final void
init
(ProtocolStack<?>.Ptr ptr) Initializes the layer with itsProtocolStack.Ptr
.protected final boolean
SPI: Check if the recipient is open.protected ByteBufferQueue
SPI: Creates a newByteBuffer
optimally sized for network read/write operations.protected final void
onRead
(ByteBuffer data) SPI: Performed the handling of te actual read from the recipient.protected final void
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
-
Constructor Details
-
NetworkLayer
Constructor.- Parameters:
ioHub
- theIOHub
that we use.
-
-
Method Details
-
doSend
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
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
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
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
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
Gets theIOHub
that we are using.- Returns:
- the
IOHub
that we are using.
-
acquire
SPI: Acquired a newByteBuffer
optimally sized for network read/write operations.- Returns:
- a new
ByteBuffer
.
-
release
SPI: Returns a previously acquiredByteBuffer
to the pool.- Parameters:
buffer
- theByteBuffer
.
-
newByteBufferQueue
SPI: Creates a newByteBuffer
optimally sized for network read/write operations.- Returns:
- a new
ByteBuffer
optimally sized for network read/write operations.
-
stack
Returns theProtocolStack
instance that we belong to.- Returns:
- the
ProtocolStack
instance that we belong to.
-