public class NioChannelHub extends Object implements Runnable, Closeable
Channels 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
|
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).IOExceptionpublic 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 Closeableclose in interface AutoCloseableIOExceptionpublic void run()
close() is called and the selector is shut down.protected void onSelected(SelectionKey key)
public Selector getSelector()
Copyright © 2004-2014. All Rights Reserved.