|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.pipeline.Pipeline
public class Pipeline
This class represents a processing system consisting of a number of stages and branches. Each stage contains a queue and manages one or more threads that process data in that stage's queue and allow processed data to be passed along to subsequent stages and onto branches of the pipeline.
This class allows all stages in the pipeline to be managed collectively with methods to start and stop processing for all stages, as well as a simple framework for asynchronous event-based communication between stages.
Field Summary | |
---|---|
static String |
MAIN_BRANCH
The branch key for the main line of production. |
Constructor Summary | |
---|---|
Pipeline()
Creates and initializes a new Pipeline. |
Method Summary | |
---|---|
void |
addBranch(String key,
Pipeline branch)
Adds a branch to the pipeline. |
void |
addLifecycleJob(PipelineLifecycleJob job)
Adds a job to be onStart on startup to the pipeline. |
void |
addStage(Stage stage,
StageDriverFactory driverFactory)
Adds a Stage object to the end of this Pipeline. |
void |
finish()
This method iterates over the stages in the pipeline, looking up a StageDriver
for each stage and using that driver to request that the stage finish
execution. |
Map<String,Pipeline> |
getBranches()
Returns an unmodifiable map of branch pipelines, keyed by branch identifier. |
Feeder |
getBranchFeeder(String branch)
Return the source feeder for the specified pipeline branch. |
Feeder |
getDownstreamFeeder(Stage stage)
This method is used by a stage driver to pass data from one stage to the next. |
Object |
getEnv(String key)
A StageContext implementation provides a global environment for the stages being run. |
Pipeline |
getParent()
Returns the parent of this pipeline, if it is a branch |
Collection<StageEventListener> |
getRegisteredListeners()
Returns the collection of StageEventListener s registered with the
context. |
Feeder |
getSourceFeeder()
Returns a feeder for the first stage if the pipeline is not empty |
StageDriver |
getStageDriver(Stage stage)
Return the StageDriver for the specified Stage. |
List<StageDriver> |
getStageDrivers()
Returns an unmodifiable list of stage drivers that have been added to the pipeline. |
List<Stage> |
getStages()
Returns an unmodifiable list of stages that have been added to this pipeline. |
Feeder |
getTerminalFeeder()
Gets the feeder that receives output from the final stage. |
PipelineValidator |
getValidator()
Returns the validator being used to validate the pipeline structure, or null if no validation is being performed.. |
void |
raise(EventObject ev)
Asynchronously notifies each registered listener of an event and propagates the event to any attached branches and the parent pipeline. |
void |
registerListener(StageEventListener listener)
Adds a StageEventListener to the context that will be notified by calls
to StageContext.raise(EventObject) . |
void |
run()
Runs the pipeline from start to finish. |
void |
setEnv(String key,
Object value)
Sets the value corresponding to the specified environment variable key. |
void |
setTerminalFeeder(Feeder terminalFeeder)
Sets the terminal feeder used to handle any output from the final stage. |
void |
setValidator(PipelineValidator validator)
Sets the validator used to validate the pipeline as it is contstructed. |
void |
start()
This method iterates over the stages in the pipeline, looking up a StageDriver for each stage and using that driver to start the stage. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String MAIN_BRANCH
Constructor Detail |
---|
public Pipeline()
Method Detail |
---|
public void registerListener(StageEventListener listener)
StageEventListener
to the context that will be notified by calls
to StageContext.raise(EventObject)
.
registerListener
in interface StageContext
listener
- The listener to be registered with the context.public Collection<StageEventListener> getRegisteredListeners()
StageEventListener
s registered with the
context.
getRegisteredListeners
in interface StageContext
StageEventListener
s registered with the
context.public void raise(EventObject ev)
raise
in interface StageContext
ev
- The event to be sent to registered listenerspublic Feeder getDownstreamFeeder(Stage stage)
getDownstreamFeeder
in interface StageContext
stage
- The stage from which "downstream" will be determined. Ordinarily a Stage implementation
will call this method with a reference to itself.
Feeder.VOID
if no downstream
stage exists.public Feeder getBranchFeeder(String branch)
getBranchFeeder
in interface StageContext
branch
- the string identifer of the branch for which a feeder will be retrieved
Feeder
for the first stage of the specified branchpublic Object getEnv(String key)
getEnv
in interface StageContext
public void setEnv(String key, Object value)
public final void addStage(Stage stage, StageDriverFactory driverFactory) throws ValidationException
Stage
object to the end of this Pipeline. If a
PipelineValidator
has been set using setValidator(org.apache.commons.pipeline.validation.PipelineValidator)
, it will
be used to validate that the appended Stage can consume the output of the
previous stage of the pipeline. It does NOT validate the ability or availability
of branches to consume data produced by the appended stage.
stage
- the stage to be added to the pipelinedriverFactory
- the factory that will be used to create a StageDriver
that will run the stage
ValidationException
- if there is a non-null validator set for this pipeline and an error is
encountered validating the addition of the stage to the pipeline.public final List<Stage> getStages()
public final StageDriver getStageDriver(Stage stage)
public final List<StageDriver> getStageDrivers()
public void addBranch(String key, Pipeline branch) throws ValidationException
key
- the string identifier that will be used to refer to the added branchpipeline
- the branch pipeline
ValidationException
- if the pipeline has a non-null PipelineValidator
and the branch
cannot consume the data produced for the branch by stages in the pipeline.public Map<String,Pipeline> getBranches()
public Feeder getSourceFeeder()
public Feeder getTerminalFeeder()
Feeder.VOID
public void setTerminalFeeder(Feeder terminalFeeder)
terminalFeeder
- the Feeder
that will receive any output from the final stagepublic void addLifecycleJob(PipelineLifecycleJob job)
public void start() throws StageException
StageDriver
for each stage and using that driver to start the stage.
Startups may occur sequentially or in parallel, depending upon the stage driver
used. If a the stage has not been configured with a StageDriver
,
we will use the default, non-threaded SynchronousStageDriver
.
StageException
- Thrown if there is an error during pipeline startuppublic void finish() throws StageException
StageDriver
for each stage and using that driver to request that the stage finish
execution. The StageDriver#finish(Stage)
method will block until the stage's queue is exhausted, so this method
may be used to safely finalize all stages without the risk of
losing data in the queues.
StageException
- Thrown if there is an unhandled error during stage shutdownpublic void run()
run
in interface Runnable
public PipelineValidator getValidator()
public void setValidator(PipelineValidator validator)
validator
- Validator used to validate pipeline structure.public Pipeline getParent()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |