public class NioChannelHub extends Object implements Runnable, Closeable
Channel
s through NIO select.
Through this hub, N threads can attend to M channels with a help of one selector thread.
To get the selector thread going, call the run()
method from a thread after you instantiate this object.
The run()
method will block until the hub gets closed.
Constructor and Description |
---|
NioChannelHub(ExecutorService commandProcessor) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Shuts down the selector thread and aborts all
|
void |
ensureValid()
Verifies that the selector thread is running and this hub is active.
|
Selector |
getSelector() |
NioChannelBuilder |
newChannelBuilder(String name,
ExecutorService es)
Returns a
ChannelBuilder that will add a channel to this hub. |
protected void |
onSelected(SelectionKey key)
Called when the unknown key registered to the selector is selected.
|
void |
run()
Attend to channels in the hub.
|
void |
setFrameSize(int sz) |
public NioChannelHub(ExecutorService commandProcessor) throws IOException
commandProcessor
- Executor pool that delivers received command packets to AbstractByteArrayCommandTransport.ByteArrayReceiver
.
This pool will handle the deserialization (which may block due to classloading from the other side).IOException
public void setFrameSize(int sz)
public NioChannelBuilder newChannelBuilder(String name, ExecutorService es)
ChannelBuilder
that will add a channel to this hub.
If the way the channel is built doesn't support NIO, the resulting Channel
will
use a separate thread to service its I/O.
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public void run()
close()
is called and the selector is shut down.protected void onSelected(SelectionKey key)
public Selector getSelector()
public void ensureValid() throws IOException
IOException
Copyright © 2004–2022. All rights reserved.