Class Reactor
- java.lang.Object
-
- com.cosylab.epics.caj.impl.reactor.Reactor
-
public class Reactor extends Object
Implementation of reactor pattern usingjava.nio.channels.Selector.- Version:
- $id$
- Author:
- Matej Sekoranja
-
-
Constructor Summary
Constructors Constructor Description Reactor()Creates a new instance of reactor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddisableSelectionKey(SelectionKey key)Disable selection key - sets its interest ops to 0 and stores its current interest ops (to be restored).voidenableSelectionKey(SelectionKey key)Enable selection key - restore its interest ops.booleanisShutdown()Get shutdown status.booleanprocess()Process requests.SelectionKeyregister(SelectableChannel selectableChannel, int interestOps, ReactorHandler handler)RegistersSelectableChannelto the reactor.voidsetInterestOps(AbstractSelectableChannel channel, int interestOps)ChangeSelectionKeyoperations of interest.voidshutdown()Shutdown the reactor.voidunregisterAndClose(SelectableChannel selectableChannel)DeregistersSelectableChannelfrom the reactor.
-
-
-
Constructor Detail
-
Reactor
public Reactor() throws IOExceptionCreates a new instance of reactor.- Throws:
IOException
-
-
Method Detail
-
process
public boolean process()
Process requests. NOTE: this method has to be called untilfalseis returned.- Returns:
trueif selector is stil active,falsewhen shutdown.
-
unregisterAndClose
public void unregisterAndClose(SelectableChannel selectableChannel)
DeregistersSelectableChannelfrom the reactor.- Parameters:
selectableChannel- channel to be unregistered.
-
register
public SelectionKey register(SelectableChannel selectableChannel, int interestOps, ReactorHandler handler) throws ClosedChannelException
RegistersSelectableChannelto 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)
ChangeSelectionKeyoperations of interest.- Parameters:
channel-interestOps-
-
shutdown
public void shutdown()
Shutdown the reactor.
-
isShutdown
public boolean isShutdown()
Get shutdown status.- Returns:
- shutdown status.
-
-