com.cosylab.epics.caj.impl.reactor
Class Reactor

java.lang.Object
  extended by com.cosylab.epics.caj.impl.reactor.Reactor

public class Reactor
extends Object

Implementation of reactor pattern using java.nio.channels.Selector.

Version:
$id$
Author:
Matej Sekoranja

Constructor Summary
Reactor()
          Creates a new instance of reactor.
 
Method Summary
 void disableSelectionKey(SelectionKey key)
          Disable selection key - sets its interest ops to 0 and stores its current interest ops (to be restored).
 void enableSelectionKey(SelectionKey key)
          Enable selection key - restore its interest ops.
 boolean isShutdown()
          Get shutdown status.
 boolean process()
          Process requests.
 SelectionKey register(SelectableChannel selectableChannel, int interestOps, ReactorHandler handler)
          Registers SelectableChannel to the reactor.
 void setInterestOps(AbstractSelectableChannel channel, int interestOps)
          Change SelectionKey operations of interest.
 void shutdown()
          Shutdown the reactor.
 void unregisterAndClose(SelectableChannel selectableChannel)
          Deregisters SelectableChannel from the reactor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Reactor

public Reactor()
        throws IOException
Creates a new instance of reactor.

Throws:
IOException
Method Detail

process

public boolean process()
Process requests. NOTE: this method has to be called until false is returned.

Returns:
true if selector is stil active, false when shutdown.

unregisterAndClose

public void unregisterAndClose(SelectableChannel selectableChannel)
Deregisters SelectableChannel from the reactor.

Parameters:
selectableChannel - channel to be unregistered.

register

public SelectionKey register(SelectableChannel selectableChannel,
                             int interestOps,
                             ReactorHandler handler)
                      throws ClosedChannelException
Registers SelectableChannel to the reactor.

Parameters:
selectableChannel - channel to be registered.
interestOps - operations suppored by channel (i.e. operations of interest).
handler - handle to process requests.
Returns:
selector selection key.
Throws:
ClosedChannelException

disableSelectionKey

public void disableSelectionKey(SelectionKey key)
Disable selection key - sets its interest ops to 0 and stores its current interest ops (to be restored). NOTE: to be called only (otherwise it can block) when select is not pending

Parameters:
key - selection key to be disabled.

enableSelectionKey

public void enableSelectionKey(SelectionKey key)
Enable selection key - restore its interest ops. NOTE: can be called when select is pending

Parameters:
key - selection key to be enabled.

setInterestOps

public void setInterestOps(AbstractSelectableChannel channel,
                           int interestOps)
Change SelectionKey operations of interest.

Parameters:
channel -
interestOps -

shutdown

public void shutdown()
Shutdown the reactor.


isShutdown

public boolean isShutdown()
Get shutdown status.

Returns:
shutdown status.


Copyright © 2004-2013 Cosylab. All Rights Reserved.