Class NioSelectorGroup

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

public class NioSelectorGroup extends Object implements NioGroup
The NioSelectorGroup is a group of selectors for interfacing with java nio. When it is started it will create the configured number of selectors. Each selector will be running in a dedicated thread. Server connections can be bound using the bindServerChannel(InetSocketAddress, ChannelFactory) method. Client connections can be opened using the openChannel(InetSocketAddress, ChannelFactory) method.

The logic specific to a particular channel is provided by the ChannelFactory passed to the method when the channel is created. This is what allows an NioSelectorGroup to support different channel types.

  • Constructor Details

    • NioSelectorGroup

      public NioSelectorGroup(ThreadFactory threadFactory, int selectorCount, Function<Supplier<NioSelector>,EventHandler> eventHandlerFunction) throws IOException
      This will create an NioSelectorGroup with no dedicated acceptors. All server channels will be handled by the same selectors that are handling child channels.
      Parameters:
      threadFactory - factory to create selector threads
      selectorCount - the number of selectors to be created
      eventHandlerFunction - function for creating event handlers
      Throws:
      IOException - occurs if there is a problem while opening a java.nio.Selector
    • NioSelectorGroup

      public NioSelectorGroup(ThreadFactory acceptorThreadFactory, int dedicatedAcceptorCount, ThreadFactory selectorThreadFactory, int selectorCount, Function<Supplier<NioSelector>,EventHandler> eventHandlerFunction) throws IOException
      This will create an NioSelectorGroup with dedicated acceptors. All server channels will be handled by a group of selectors dedicated to accepting channels. These accepted channels will be handed off the non-server selectors.
      Parameters:
      acceptorThreadFactory - factory to create acceptor selector threads
      dedicatedAcceptorCount - the number of dedicated acceptor selectors to be created
      selectorThreadFactory - factory to create non-acceptor selector threads
      selectorCount - the number of non-acceptor selectors to be created
      eventHandlerFunction - function for creating event handlers
      Throws:
      IOException - occurs if there is a problem while opening a java.nio.Selector
  • Method Details