Interface NioChannelHandler

  • All Known Implementing Classes:
    BytesWriteHandler, DelegatingHandler

    public interface NioChannelHandler
    Implements the application specific logic for handling channel operations.
    • Method Detail

      • channelRegistered

        void channelRegistered()
        This method is called when the channel is registered with its selector.
      • createWriteOperation

        WriteOperation createWriteOperation​(SocketChannelContext context,
                                            java.lang.Object message,
                                            java.util.function.BiConsumer<java.lang.Void,​java.lang.Exception> listener)
        This method is called when a message is queued with a channel. It can be called from any thread. This method should validate that the message is a valid type and return a write operation object to be queued with the channel
        Parameters:
        context - the channel context
        message - the message
        listener - the listener to be called when the message is sent
        Returns:
        the write operation to be queued
      • writeToBytes

        java.util.List<FlushOperation> writeToBytes​(WriteOperation writeOperation)
        This method is called on the event loop thread. It should serialize a write operation object to bytes that can be flushed to the raw nio channel.
        Parameters:
        writeOperation - to be converted to bytes
        Returns:
        the operations to flush the bytes to the channel
      • pollFlushOperations

        java.util.List<FlushOperation> pollFlushOperations()
        Returns any flush operations that are ready to flush. This exists as a way to check if any flush operations were produced during a read call.
        Returns:
        flush operations
      • consumeReads

        int consumeReads​(InboundChannelBuffer channelBuffer)
                  throws java.io.IOException
        This method handles bytes that have been read from the network. It should return the number of bytes consumed so that they can be released.
        Parameters:
        channelBuffer - of bytes read from the network
        Returns:
        the number of bytes consumed
        Throws:
        java.io.IOException - if an exception occurs
      • closeNow

        boolean closeNow()
        This method indicates if the underlying channel should be closed.
        Returns:
        if the channel should be closed
      • close

        void close()
            throws java.io.IOException
        Throws:
        java.io.IOException