Class ChannelContext<S extends SelectableChannel & NetworkChannel>

java.lang.Object
org.elasticsearch.nio.ChannelContext<S>
Type Parameters:
S - the type of channel
Direct Known Subclasses:
ServerChannelContext, SocketChannelContext

public abstract class ChannelContext<S extends SelectableChannel & NetworkChannel> extends Object
Implements the logic related to interacting with a java.nio channel. For example: registering with a selector, managing the selection key, closing, etc is implemented by this class or its subclasses.
  • Field Details

  • Method Details

    • register

      protected void register() throws IOException
      Throws:
      IOException
    • channelActive

      protected void channelActive() throws IOException
      Throws:
      IOException
    • getSelectionKey

      protected SelectionKey getSelectionKey()
    • setSelectionKey

      public void setSelectionKey(SelectionKey selectionKey)
    • closeFromSelector

      public void closeFromSelector() throws IOException
      This method cleans up any context resources that need to be released when a channel is closed. It should only be called by the selector thread.
      Throws:
      IOException - during channel / context close
    • addCloseListener

      public void addCloseListener(BiConsumer<Void,Exception> listener)
      Add a listener that will be called when the channel is closed.
      Parameters:
      listener - to be called
    • isOpen

      public boolean isOpen()
    • handleException

      protected void handleException(Exception e)
    • closeChannel

      public abstract void closeChannel()
      Schedules a channel to be closed by the selector event loop with which it is registered. If the channel is open and the state can be transitioned to closed, the close operation will be scheduled with the event loop. Depending on the underlying protocol of the channel, a close operation might simply close the socket channel or may involve reading and writing messages.
    • getSelector

      public abstract NioSelector getSelector()
    • getChannel

      public abstract NioChannel getChannel()