FileDocCategorySizeDatePackage
DispatcherN.javaAPI DocSun JDK 1.5.0 Example2896Sat Jan 08 15:08:43 GMT 2005None

DispatcherN

public class DispatcherN extends Object implements Dispatcher
A Multi-threaded dispatcher.

In this example, one thread does accepts, and the second does read/writes.

author
Mark Reinhold
author
Brad R. Wetmore
version
1.2, 04/07/26

Fields Summary
private Selector
sel
private Object
gate
Constructors Summary
DispatcherN()

	sel = Selector.open();
    
Methods Summary
private voiddispatch()


         
	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);
	}
	synchronized (gate) { }
    
public voidregister(java.nio.channels.SelectableChannel ch, int ops, Handler h)

	synchronized (gate) {
	    sel.wakeup();
	    ch.register(sel, ops, h);
	}
    
public voidrun()

	for (;;) {
	    try {
		dispatch();
	    } catch (IOException x) {
		x.printStackTrace();
	    }
	}