Class SynchronousReactor

  • All Implemented Interfaces:
    Reactor

    public class SynchronousReactor
    extends java.lang.Object
    implements Reactor
    The SynchronousReactor object is used to execute the ready operations of within a single synchronous thread. This is used when the I/O operations to be performed do not require much time to execute and so will not block the execution thread.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private OperationDistributor exchange
      This is used to distribute the ready operations for execution.
      private java.util.concurrent.Executor executor
      This is used to execute the operations that ready to run.
    • Constructor Summary

      Constructors 
      Constructor Description
      SynchronousReactor()
      Constructor for the SynchronousReactor object.
      SynchronousReactor​(boolean cancel)
      Constructor for the SynchronousReactor object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void process​(Operation task)
      This method is used to execute the provided operation without the need to specifically check for I/O events.
      void process​(Operation task, int require)
      This method is used to execute the provided operation when there is an I/O event that task is interested in.
      void stop()
      This is used to stop the reactor so that further requests to execute operations does nothing.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • exchange

        private final OperationDistributor exchange
        This is used to distribute the ready operations for execution.
      • executor

        private final java.util.concurrent.Executor executor
        This is used to execute the operations that ready to run.
    • Constructor Detail

      • SynchronousReactor

        public SynchronousReactor()
                           throws java.io.IOException
        Constructor for the SynchronousReactor object. This is used to create a reactor that does not require thread pooling to execute the ready operations. All I/O operations are run in the selection thread and should complete quickly.
        Throws:
        java.io.IOException
      • SynchronousReactor

        public SynchronousReactor​(boolean cancel)
                           throws java.io.IOException
        Constructor for the SynchronousReactor object. This is used to create a reactor that does not require thread pooling to execute the ready operations. All I/O operations are run in the selection thread and should complete quickly.
        Parameters:
        cancel - determines the selection key should be cancelled
        Throws:
        java.io.IOException
    • Method Detail

      • process

        public void process​(Operation task)
                     throws java.io.IOException
        This method is used to execute the provided operation without the need to specifically check for I/O events. This is used if the operation knows that the SelectableChannel is ready, or if the I/O operation can be performed without knowing if the channel is ready. Typically this is an efficient means to perform a poll rather than a select on the channel.
        Specified by:
        process in interface Reactor
        Parameters:
        task - this is the task to execute immediately
        Throws:
        java.io.IOException
      • process

        public void process​(Operation task,
                            int require)
                     throws java.io.IOException
        This method is used to execute the provided operation when there is an I/O event that task is interested in. This will used the operations SelectableChannel object to determine the events that are ready on the channel. If this reactor is interested in any of the ready events then the task is executed.
        Specified by:
        process in interface Reactor
        Parameters:
        task - this is the task to execute on interested events
        require - this is the bit-mask value for interested events
        Throws:
        java.io.IOException
      • stop

        public void stop()
                  throws java.io.IOException
        This is used to stop the reactor so that further requests to execute operations does nothing. This will clean up all of the reactors resources and unregister any operations that are currently awaiting execution. This should be used to ensure any threads used by the reactor graceful stop.
        Specified by:
        stop in interface Reactor
        Throws:
        java.io.IOException