org.indi.reactor
Class Reactor

java.lang.Object
  extended by org.indi.reactor.Reactor

public class Reactor
extends java.lang.Object

A simple implementation of the reactor pattern (similar to eventloop /event driven system / event demultiplexer) around the java newIO system. Just register event handlers with the reactor and call handle events frequntly. The callbackmethods of the event handlers will be called as soon as the corresponding events have been detected. See http://www.cs.wustl.edu/~schmidt/PDF/reactor-siemens.pdf for a basic introduction to the concept.

Author:
Dirk Hünniger

Field Summary
protected  java.nio.channels.Selector selector
          The Selector used by the Reactor to listen for IO events
 
Constructor Summary
Reactor()
          Class constructor
 
Method Summary
 int handleEvents(long timeout)
          Call the methods frequently.
 void register(EventHandler h, int ops)
          Registers a new IO-EventHandler with the reactor
 void register(QueueHandler h)
          Register a new Queue-EventHandler with the reactor
 void register(TimerHandler h)
          Register a new Timer-EventHanlder with the reactor
 void unregister(EventHandler h)
          Unregister a IO-EventHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

selector

protected java.nio.channels.Selector selector
The Selector used by the Reactor to listen for IO events

Constructor Detail

Reactor

public Reactor()
        throws java.io.IOException
Class constructor

Throws:
java.io.IOException
Method Detail

register

public void register(EventHandler h,
                     int ops)
Registers a new IO-EventHandler with the reactor

Parameters:
h - EventHandler to be installed
ops - Bitmask describing the IO Events to listen to.

register

public void register(QueueHandler h)
Register a new Queue-EventHandler with the reactor

Parameters:
h - QueueHandler to be regsitered

register

public void register(TimerHandler h)
Register a new Timer-EventHanlder with the reactor

Parameters:
h - the TimeHandler to be registered

unregister

public void unregister(EventHandler h)
Unregister a IO-EventHandler

Parameters:
h -

handleEvents

public int handleEvents(long timeout)
                 throws java.io.IOException
Call the methods frequently. In this methods all events are detected and dispached to the approriate EventHandlers

Parameters:
timeout - the maximum time to wait for events in miliseconds
Returns:
Number of IO events handled
Throws:
java.io.IOException


Copyright © 2008. All Rights Reserved.