Package org.epics.ca.impl.reactor
Class Reactor
- java.lang.Object
-
- org.epics.ca.impl.reactor.Reactor
-
public class Reactor extends java.lang.ObjectImplementation of reactor pattern usingjava.nio.channels.Selector.
-
-
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(java.nio.channels.SelectionKey key)Disable selection key - sets its interest ops to 0 and stores its current interest ops (to be restored).voidenableSelectionKey(java.nio.channels.SelectionKey key)Enable selection key - restore its interest ops.booleanisShutdown()Get shutdown status.booleanprocess()Process requests.java.nio.channels.SelectionKeyregister(java.nio.channels.SelectableChannel selectableChannel, int interestOps, ReactorHandler handler)RegistersSelectableChannelto the reactor.voidsetInterestOps(java.nio.channels.spi.AbstractSelectableChannel channel, int interestOps)ChangeSelectionKeyoperations of interest.voidshutdown()Shutdown the reactor.voidunregisterAndClose(java.nio.channels.SelectableChannel selectableChannel)UnregistersSelectableChannelfrom the reactor.
-
-
-
Method Detail
-
process
public boolean process()
Process requests. NOTE: this method has to be called untilfalseis returned.- Returns:
trueif selector is still active,falsewhen shutdown.
-
unregisterAndClose
public void unregisterAndClose(java.nio.channels.SelectableChannel selectableChannel)
UnregistersSelectableChannelfrom the reactor.- Parameters:
selectableChannel- channel to be unregistered.
-
register
public java.nio.channels.SelectionKey register(java.nio.channels.SelectableChannel selectableChannel, int interestOps, ReactorHandler handler) throws java.nio.channels.ClosedChannelExceptionRegistersSelectableChannelto the reactor.- Parameters:
selectableChannel- channel to be registered.interestOps- operations supported by channel (i.e. operations of interest).handler- handle to process requests.- Returns:
- selector selection key.
- Throws:
java.nio.channels.ClosedChannelException- Channel closed
-
disableSelectionKey
public void disableSelectionKey(java.nio.channels.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(java.nio.channels.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(java.nio.channels.spi.AbstractSelectableChannel channel, int interestOps)ChangeSelectionKeyoperations of interest.- Parameters:
channel- channelinterestOps- interest ops
-
shutdown
public void shutdown()
Shutdown the reactor.
-
isShutdown
public boolean isShutdown()
Get shutdown status.- Returns:
- shutdown status.
-
-