public final class NioNetworking extends Object implements Networking
Networking
implementation that makes use of
Selector
to have a limited set of io threads, handle
an arbitrary number of connections.
Each NioChannel
has 2 parts:
NioInboundPipeline
: triggered by the NioThread when data is available
in the socket. The NioInboundPipeline takes care of reading data from the socket
and calling the appropriate
InboundHandler
NioOutboundPipeline
: triggered by the NioThread when either space
is available in the socket for writing, or when there is something that needs to
be written e.g. a Packet. The NioOutboundPipeline takes care of calling the
appropriate OutboundHandler
to convert the OutboundFrame
to bytes
in in the ByteBuffer and writing it to the socket.
NioThread
blocks on the Selector, but it can be put in a
'selectNow' mode that makes it spinning on the selector. This is an experimental
feature and will cause the io threads to run hot. For this reason, when this feature
is enabled, the number of io threads should be reduced (preferably 1).Modifier and Type | Class and Description |
---|---|
static class |
NioNetworking.Context |
Constructor and Description |
---|
NioNetworking(NioNetworking.Context ctx) |
Modifier and Type | Method and Description |
---|---|
Set<NioChannel> |
getChannels() |
NioThread[] |
getInputThreads() |
IOBalancer |
getIOBalancer() |
NioThread[] |
getOutputThreads() |
Channel |
register(SocketChannel socketChannel,
boolean clientMode)
Registers the SocketChannel to the EventLoop group and returns the
created Channel.
|
void |
shutdown()
Shuts down Networking.
|
void |
start()
Starts Networking.
|
public NioNetworking(NioNetworking.Context ctx)
public NioThread[] getInputThreads()
public NioThread[] getOutputThreads()
public Set<NioChannel> getChannels()
public IOBalancer getIOBalancer()
public void start()
Networking
start
in interface Networking
public void shutdown()
Networking
shutdown
in interface Networking
public Channel register(SocketChannel socketChannel, boolean clientMode) throws IOException
Networking
Channel.start()
needs to be called.
In the future we need to think about passing the socket channel because
it binds Networking to tcp and this is not desirable.register
in interface Networking
socketChannel
- the socketChannel to registerclientMode
- if the channel is made in clientMode or server modeIOException
- when something failed while registering the
socketChannelCopyright © 2018 Hazelcast, Inc.. All Rights Reserved.