Package org.elasticsearch.nio
Class NioSelectorGroup
- java.lang.Object
-
- org.elasticsearch.nio.NioSelectorGroup
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,NioGroup
public class NioSelectorGroup extends java.lang.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 thebindServerChannel(InetSocketAddress, ChannelFactory)method. Client connections can be opened using theopenChannel(InetSocketAddress, ChannelFactory)method.The logic specific to a particular channel is provided by the
ChannelFactorypassed to the method when the channel is created. This is what allows an NioSelectorGroup to support different channel types.
-
-
Constructor Summary
Constructors Constructor Description NioSelectorGroup(java.util.concurrent.ThreadFactory acceptorThreadFactory, int dedicatedAcceptorCount, java.util.concurrent.ThreadFactory selectorThreadFactory, int selectorCount, java.util.function.Function<java.util.function.Supplier<NioSelector>,EventHandler> eventHandlerFunction)This will create an NioSelectorGroup with dedicated acceptors.NioSelectorGroup(java.util.concurrent.ThreadFactory threadFactory, int selectorCount, java.util.function.Function<java.util.function.Supplier<NioSelector>,EventHandler> eventHandlerFunction)This will create an NioSelectorGroup with no dedicated acceptors.
-
Method Summary
Modifier and Type Method Description <S extends NioServerSocketChannel>
SbindServerChannel(java.net.InetSocketAddress address, ChannelFactory<S,?> factory)Opens and binds a server channel to accept incoming connections.voidclose()<S extends NioSocketChannel>
SopenChannel(java.net.InetSocketAddress address, ChannelFactory<?,S> factory)Opens a outgoing client channel.
-
-
-
Constructor Detail
-
NioSelectorGroup
public NioSelectorGroup(java.util.concurrent.ThreadFactory threadFactory, int selectorCount, java.util.function.Function<java.util.function.Supplier<NioSelector>,EventHandler> eventHandlerFunction) throws java.io.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:
java.io.IOException- occurs if there is a problem while opening a java.nio.Selector
-
NioSelectorGroup
public NioSelectorGroup(java.util.concurrent.ThreadFactory acceptorThreadFactory, int dedicatedAcceptorCount, java.util.concurrent.ThreadFactory selectorThreadFactory, int selectorCount, java.util.function.Function<java.util.function.Supplier<NioSelector>,EventHandler> eventHandlerFunction) throws java.io.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:
java.io.IOException- occurs if there is a problem while opening a java.nio.Selector
-
-
Method Detail
-
bindServerChannel
public <S extends NioServerSocketChannel> S bindServerChannel(java.net.InetSocketAddress address, ChannelFactory<S,?> factory) throws java.io.IOException
Description copied from interface:NioGroupOpens and binds a server channel to accept incoming connections.- Specified by:
bindServerChannelin interfaceNioGroup- Throws:
java.io.IOException
-
openChannel
public <S extends NioSocketChannel> S openChannel(java.net.InetSocketAddress address, ChannelFactory<?,S> factory) throws java.io.IOException
Description copied from interface:NioGroupOpens a outgoing client channel.- Specified by:
openChannelin interfaceNioGroup- Throws:
java.io.IOException
-
-