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 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
  • Constructor Details

    • NetworkLayer

      public NetworkLayer(@NonNull IOHub ioHub)
      Constructor.
      Parameters:
      ioHub - the IOHub that we use.
  • Method Details

    • doSend

      public final void doSend(@NonNull ByteBuffer data) throws IOException
      Sends data to the lower layer.
      Specified by:
      doSend in interface ProtocolLayer.Send
      Parameters:
      data - the data to send. Any data consumed from the ByteBuffer can be assumed as processed. Any data not consumed from the ByteBuffer 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 the ByteBuffer can be assumed as processed. Any data not consumed from the ByteBuffer 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 the ByteBuffer can be assumed as processed. Any data not consumed from the ByteBuffer 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 its ProtocolStack.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 to ProtocolLayer.start().
      Specified by:
      init in interface ProtocolLayer
      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 interface ProtocolLayer
      Throws:
      IOException - if something goes wrong.
    • getIoHub

      @NonNull public IOHub getIoHub()
      Gets the IOHub that we are using.
      Returns:
      the IOHub that we are using.
    • acquire

      protected ByteBuffer acquire()
      SPI: Acquired a new ByteBuffer optimally sized for network read/write operations.
      Returns:
      a new ByteBuffer.
    • release

      protected void release(ByteBuffer buffer)
      SPI: Returns a previously acquired ByteBuffer to the pool.
      Parameters:
      buffer - the ByteBuffer.
    • newByteBufferQueue

      protected ByteBufferQueue newByteBufferQueue()
      SPI: Creates a new ByteBuffer optimally sized for network read/write operations.
      Returns:
      a new ByteBuffer optimally sized for network read/write operations.
    • stack

      protected ProtocolStack<?> stack()
      Returns the ProtocolStack instance that we belong to.
      Returns:
      the ProtocolStack instance that we belong to.