org.simpleframework.transport.reactor
Class ExecutorReactor

java.lang.Object
  extended by org.simpleframework.transport.reactor.ExecutorReactor
All Implemented Interfaces:
Reactor

public class ExecutorReactor
extends java.lang.Object
implements Reactor

The ExecutorReactor is used to schedule operation for execution using an Executor implementation. This can be useful when the operations performed are time intensive. For example if the operations performed a read of the underlying channel and then had to parse the contents of the payload. Such operations would reduce the performance of the reactor if it could not delegate to some other form of executor, as it would delay their execution.

Author:
Niall Gallagher

Constructor Summary
ExecutorReactor(java.util.concurrent.Executor executor)
          Constructor for the ExecutorReactor object.
ExecutorReactor(java.util.concurrent.Executor executor, int count)
          Constructor for the ExecutorReactor object.
ExecutorReactor(java.util.concurrent.Executor executor, int count, long expiry)
          Constructor for the ExecutorReactor object.
 
Method Summary
 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
 

Constructor Detail

ExecutorReactor

public ExecutorReactor(java.util.concurrent.Executor executor)
                throws java.io.IOException
Constructor for the ExecutorReactor object. This is used to create a reactor that can delegate to the executor. This also accepts the operations it is interested in, the value is taken from the SelectionKey object. A bit mask can be used to show interest in several operations at once.

Parameters:
executor - this is the executor used to run the operations
Throws:
java.io.IOException

ExecutorReactor

public ExecutorReactor(java.util.concurrent.Executor executor,
                       int count)
                throws java.io.IOException
Constructor for the ExecutorReactor object. This is used to create a reactor that can delegate to the executor. This also accepts the operations it is interested in, the value is taken from the SelectionKey object. A bit mask can be used to show interest in several operations at once.

Parameters:
executor - this is the executor used to run the operations
count - this is the number of distributors to be used
Throws:
java.io.IOException

ExecutorReactor

public ExecutorReactor(java.util.concurrent.Executor executor,
                       int count,
                       long expiry)
                throws java.io.IOException
Constructor for the ExecutorReactor object. This is used to create a reactor that can delegate to the executor. This also accepts the operations it is interested in, the value is taken from the SelectionKey object. A bit mask can be used to show interest in several operations at once.

Parameters:
executor - this is the executor used to run the operations
count - this is the number of distributors to be used
expiry - the length of time to maintain and idle operation
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 gracefully stop.

Specified by:
stop in interface Reactor
Throws:
java.io.IOException