FileDocCategorySizeDatePackage
Dispatcher1.javaAPI DocSun JDK 1.5.0 Example2816Sat Jan 08 15:08:43 GMT 2005None

Dispatcher1

public class Dispatcher1 extends Object implements Dispatcher
A single-threaded dispatcher.

When a SelectionKey is ready, it dispatches the job in this thread.

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

Fields Summary
private Selector
sel
Constructors Summary
Dispatcher1()

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

	ch.register(sel, ops, h);
    
public voidrun()

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