org.apache.commons.pipeline.driver
Class ThreadPoolStageDriver

java.lang.Object
  extended by org.apache.commons.pipeline.driver.AbstractStageDriver
      extended by org.apache.commons.pipeline.driver.ThreadPoolStageDriver
All Implemented Interfaces:
StageDriver

public class ThreadPoolStageDriver
extends AbstractStageDriver

This StageDriver implementation uses a pool of threads to process objects from an input queue.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.commons.pipeline.StageDriver
StageDriver.State
 
Field Summary
 
Fields inherited from class org.apache.commons.pipeline.driver.AbstractStageDriver
context, currentState, errors, faultTolerance, processingExceptions, stage
 
Constructor Summary
ThreadPoolStageDriver(Stage stage, StageContext context, BlockingQueue queue, long timeout, FaultTolerance faultTolerance, int numThreads)
          Creates a new ThreadPoolStageDriver.
 
Method Summary
 void finish()
          Causes processing to shut down gracefully.
 Feeder getFeeder()
          Return the Feeder used to feed data to the queue of objects to be processed.
 int getNumThreads()
          Returns the number of threads allocated to the thread pool.
 int getQueueSize()
          Get the size of the queue used by this StageDriver.
 long getTimeout()
          Get the timeout value (in milliseconds) used by this StageDriver on thread termination.
 void start()
          Start the processing of the stage.
 
Methods inherited from class org.apache.commons.pipeline.driver.AbstractStageDriver
getFatalErrors, getFaultTolerance, getProcessingExceptions, getStage, getState, isInState, recordFatalError, recordProcessingException, setFaultTolerance, setState, testAndSetState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadPoolStageDriver

public ThreadPoolStageDriver(Stage stage,
                             StageContext context,
                             BlockingQueue queue,
                             long timeout,
                             FaultTolerance faultTolerance,
                             int numThreads)
Creates a new ThreadPoolStageDriver.

Parameters:
stage - The stage that the driver will run
context - the context in which to run the stage
queue - The object queue to use for storing objects prior to processing. The default is LinkedBlockingQueue
timeout - The amount of time, in milliseconds, that the worker thread will wait before checking the processing state if no objects are available in the thread's queue.
faultTolerance - Flag determining the behavior of the driver when an error is encountered in execution of Stage.process(Object). If this is set to false, any exception thrown during Stage.process(Object) will cause the worker thread to halt without executing Stage.postprocess() (Stage.release() will be called.)
numThreads - Number of threads that will be simultaneously reading from queue
Method Detail

getFeeder

public Feeder getFeeder()
Return the Feeder used to feed data to the queue of objects to be processed.

Specified by:
getFeeder in interface StageDriver
Specified by:
getFeeder in class AbstractStageDriver
Returns:
The feeder for objects processed by this driver's stage.

start

public void start()
           throws StageException
Start the processing of the stage. Creates threads to poll items from queue.

Specified by:
start in interface StageDriver
Specified by:
start in class AbstractStageDriver
Throws:
StageException - Thrown if the driver is in an illegal state during startup

finish

public void finish()
            throws StageException
Causes processing to shut down gracefully. Waits until all worker threads have completed. It is important that this method be called only after the completion of execution of finish() in the driver for the prior stage; parallel finish calls can cause the stage to shut down before all prior stages have finished processing.

Specified by:
finish in interface StageDriver
Specified by:
finish in class AbstractStageDriver
Throws:
StageException - Thrown if the driver is in an illegal state for shutdown.

getQueueSize

public int getQueueSize()
Get the size of the queue used by this StageDriver.

Returns:
the queue capacity

getTimeout

public long getTimeout()
Get the timeout value (in milliseconds) used by this StageDriver on thread termination.

Returns:
the timeout setting in milliseconds

getNumThreads

public int getNumThreads()
Returns the number of threads allocated to the thread pool.



Copyright © 2004-2009 The Apache Software Foundation. All Rights Reserved.