Class NetworkLayer

    • Constructor Detail

      • NetworkLayer

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

      • 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.
      • 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.