Package org.elasticsearch.nio
Class NioSelectorGroup
java.lang.Object
org.elasticsearch.nio.NioSelectorGroup
- All Implemented Interfaces:
Closeable,AutoCloseable,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 Summary
ConstructorsConstructorDescriptionNioSelectorGroup(ThreadFactory acceptorThreadFactory, int dedicatedAcceptorCount, ThreadFactory selectorThreadFactory, int selectorCount, Function<Supplier<NioSelector>, EventHandler> eventHandlerFunction) This will create an NioSelectorGroup with dedicated acceptors.NioSelectorGroup(ThreadFactory threadFactory, int selectorCount, Function<Supplier<NioSelector>, EventHandler> eventHandlerFunction) This will create an NioSelectorGroup with no dedicated acceptors. -
Method Summary
Modifier and TypeMethodDescription<S extends NioServerSocketChannel>
SbindServerChannel(InetSocketAddress address, ChannelFactory<S, ?> factory) Opens and binds a server channel to accept incoming connections.voidclose()<S extends NioSocketChannel>
SopenChannel(InetSocketAddress address, ChannelFactory<?, S> factory) Opens a outgoing client channel.
-
Constructor Details
-
NioSelectorGroup
public NioSelectorGroup(ThreadFactory threadFactory, int selectorCount, Function<Supplier<NioSelector>, EventHandler> eventHandlerFunction) throws IOExceptionThis 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 threadsselectorCount- the number of selectors to be createdeventHandlerFunction- 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 IOExceptionThis 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 threadsdedicatedAcceptorCount- the number of dedicated acceptor selectors to be createdselectorThreadFactory- factory to create non-acceptor selector threadsselectorCount- the number of non-acceptor selectors to be createdeventHandlerFunction- function for creating event handlers- Throws:
IOException- occurs if there is a problem while opening a java.nio.Selector
-
-
Method Details
-
bindServerChannel
public <S extends NioServerSocketChannel> S bindServerChannel(InetSocketAddress address, ChannelFactory<S, ?> factory) throws IOExceptionDescription copied from interface:NioGroupOpens and binds a server channel to accept incoming connections.- Specified by:
bindServerChannelin interfaceNioGroup- Throws:
IOException
-
openChannel
public <S extends NioSocketChannel> S openChannel(InetSocketAddress address, ChannelFactory<?, S> factory) throws IOExceptionDescription copied from interface:NioGroupOpens a outgoing client channel.- Specified by:
openChannelin interfaceNioGroup- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceNioGroup- Throws:
IOException
-