Class NioSelector

java.lang.Object
org.elasticsearch.nio.NioSelector
All Implemented Interfaces:
Closeable, AutoCloseable

public class NioSelector extends Object implements Closeable
This is a nio selector implementation. This selector wraps a raw nio Selector. When you call runLoop(), the selector will run until close() is called. This instance handles closing of channels. Users should call queueChannelClose(NioChannel) to schedule a channel for close by this selector.
  • Constructor Details

  • Method Details

    • getIoBuffer

      public ByteBuffer getIoBuffer()
      Returns a cached direct byte buffer for network operations. It is cleared on every get call.
      Returns:
      the byte buffer
    • getTaskScheduler

      public TaskScheduler getTaskScheduler()
    • rawSelector

      public Selector rawSelector()
    • isOpen

      public boolean isOpen()
    • isRunning

      public boolean isRunning()
    • isOnCurrentThread

      public boolean isOnCurrentThread()
    • assertOnSelectorThread

      public void assertOnSelectorThread()
    • runLoop

      public void runLoop()
      Starts this selector. The selector will run until close() is called.
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • queueWrite

      public void queueWrite(WriteOperation writeOperation)
      Queues a write operation to be handled by the event loop. This can be called by any thread and is the api available for non-selector threads to schedule writes. When invoked from the selector thread the write will be executed right away.
      Parameters:
      writeOperation - to be queued
    • queueChannelClose

      public void queueChannelClose(NioChannel channel)
    • scheduleForRegistration

      public void scheduleForRegistration(NioChannel channel)
      Schedules a NioChannel to be registered with this selector. The channel will by queued and eventually registered next time through the event loop.
      Parameters:
      channel - to register
    • executeListener

      public <V> void executeListener(BiConsumer<V,Exception> listener, V value)
      Executes a success listener with consistent exception handling. This can only be called from current selector thread.
      Parameters:
      listener - to be executed
      value - to provide to listener
    • executeFailedListener

      public <V> void executeFailedListener(BiConsumer<V,Exception> listener, Exception exception)
      Executes a failed listener with consistent exception handling. This can only be called from current selector thread.
      Parameters:
      listener - to be executed
      exception - to provide to listener