Dispatcher1public class Dispatcher1 extends Object implements DispatcherA single-threaded dispatcher.
When a SelectionKey is ready, it dispatches the job in this
thread. |
Fields Summary |
---|
private Selector | sel |
Constructors Summary |
---|
Dispatcher1()
sel = Selector.open();
|
Methods Summary |
---|
private void | dispatch()
sel.select();
for (Iterator i = sel.selectedKeys().iterator(); i.hasNext(); ) {
SelectionKey sk = (SelectionKey)i.next();
i.remove();
Handler h = (Handler)sk.attachment();
h.handle(sk);
}
| public void | register(java.nio.channels.SelectableChannel ch, int ops, Handler h)
ch.register(sel, ops, h);
| public void | run()
for (;;) {
try {
dispatch();
} catch (IOException x) {
x.printStackTrace();
}
}
|
|