org.indi.reactor
Class SimpleEventHandler

java.lang.Object
  extended by org.indi.reactor.SimpleEventHandler
All Implemented Interfaces:
EventHandler
Direct Known Subclasses:
Acceptor, Connector, OutputQueue

public class SimpleEventHandler
extends java.lang.Object
implements EventHandler

A minimal implementation of the EventHandler interface.

Author:
Dirk Hünniger

Field Summary
protected  java.nio.channels.SelectableChannel channel
          The channel the handler is associated with
protected  Reactor reactor
          the reactor the handler is registered with
protected  int registeredOperations
          bitmask of the operation the handler is registered for
 
Constructor Summary
SimpleEventHandler(Reactor r, java.nio.channels.SelectableChannel ch)
          class constructor
 
Method Summary
 java.nio.channels.SelectableChannel channel()
           
 void onAccept()
          Called by the reactor whenever a new connection is ready to be accepted (passive connection establishment)
 void onClose()
          Called by the reactor when the handler is removed
 void onConnect()
          Called by the reactor whenever a new Connection is ready to be estabished (active connection establishment)
 void onRead()
          Called by the reactor whenever data is ready for reading.
 void onWrite()
          Called by the reactor whenever a connection is ready for writing
 void register(int ops)
          Register the handler with the reactor for certain IO events
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

channel

protected java.nio.channels.SelectableChannel channel
The channel the handler is associated with


reactor

protected Reactor reactor
the reactor the handler is registered with


registeredOperations

protected int registeredOperations
bitmask of the operation the handler is registered for

Constructor Detail

SimpleEventHandler

public SimpleEventHandler(Reactor r,
                          java.nio.channels.SelectableChannel ch)
class constructor

Parameters:
r - the reactor to register with
ch - the channel to use
Method Detail

register

public void register(int ops)
Description copied from interface: EventHandler
Register the handler with the reactor for certain IO events

Specified by:
register in interface EventHandler
Parameters:
ops - Bitmask descibing the events the handler is to be registered for
See Also:
EventHandler.register(int)

channel

public java.nio.channels.SelectableChannel channel()
Specified by:
channel in interface EventHandler
Returns:
the SelectableChannel for which this Handler is to be listening
See Also:
EventHandler.channel()

onRead

public void onRead()
            throws java.io.IOException
Description copied from interface: EventHandler
Called by the reactor whenever data is ready for reading.

Specified by:
onRead in interface EventHandler
Throws:
java.io.IOException
See Also:
EventHandler.onRead()

onAccept

public void onAccept()
              throws java.io.IOException,
                     java.nio.channels.ClosedChannelException
Description copied from interface: EventHandler
Called by the reactor whenever a new connection is ready to be accepted (passive connection establishment)

Specified by:
onAccept in interface EventHandler
Throws:
java.io.IOException
java.nio.channels.ClosedChannelException
See Also:
EventHandler.onAccept()

onConnect

public void onConnect()
               throws java.io.IOException
Description copied from interface: EventHandler
Called by the reactor whenever a new Connection is ready to be estabished (active connection establishment)

Specified by:
onConnect in interface EventHandler
Throws:
java.io.IOException
See Also:
EventHandler.onConnect()

onWrite

public void onWrite()
             throws java.io.IOException
Description copied from interface: EventHandler
Called by the reactor whenever a connection is ready for writing

Specified by:
onWrite in interface EventHandler
Throws:
java.io.IOException
See Also:
EventHandler.onWrite()

onClose

public void onClose()
Description copied from interface: EventHandler
Called by the reactor when the handler is removed

Specified by:
onClose in interface EventHandler
See Also:
EventHandler.onClose()


Copyright © 2008. All Rights Reserved.