Author: nuttycom Date: Fri Aug 3 10:51:49 2007 New Revision: 562531 URL: http://svn.apache.org/viewvc?view=rev&rev=562531 Log: Initial import of PipelineLifecycleJob; minor documentation fixes.
Added: commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/PipelineLifecycleJob.java (with props) Modified: commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/Feeder.java commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/Pipeline.java Modified: commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/Feeder.java URL: http://svn.apache.org/viewvc/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/Feeder.java?view=diff&rev=562531&r1=562530&r2=562531 ============================================================================== --- commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/Feeder.java (original) +++ commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/Feeder.java Fri Aug 3 10:51:49 2007 @@ -17,16 +17,13 @@ package org.apache.commons.pipeline; -import java.util.EventObject; /** * This interface represents a data channel into which objects can be fed. * Feeders act as intermediaries between stages in a pipeline and the drivers - * for subsequent stages. Each [EMAIL PROTECTED] StageDriver} implementation will + * for subsequent stages. Each [EMAIL PROTECTED] StageDriver} implementation will * ordinarily provide a custom Feeder implementation that integrates receiving * objects with its internal stage processing workflow. - * - * */ public interface Feeder { /** Modified: commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/Pipeline.java URL: http://svn.apache.org/viewvc/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/Pipeline.java?view=diff&rev=562531&r1=562530&r2=562531 ============================================================================== --- commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/Pipeline.java (original) +++ commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/Pipeline.java Fri Aug 3 10:51:49 2007 @@ -25,8 +25,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.apache.commons.pipeline.driver.SynchronousStageDriver; import org.apache.commons.pipeline.validation.PipelineValidator; import org.apache.commons.pipeline.validation.ValidationException; import org.apache.commons.pipeline.validation.ValidationFailure; @@ -49,10 +48,10 @@ public static final String MAIN_BRANCH = "main"; //The logger used for reporting by this pipeline - private final Log log = LogFactory.getLog(Pipeline.class); + //private final Log log = LogFactory.getLog(Pipeline.class); // List of stages in the pipeline, encapsulated in the drivers - // that will be used to run them. + // that will be used to onStart them. private final LinkedList<StageDriver> drivers; private final Map<Stage, StageDriver> driverMap; @@ -76,7 +75,10 @@ // Global environment variables private Map<String,Object> env = Collections.synchronizedMap(new HashMap<String,Object>()); - + + // List of jobs to be run at defined points in pipeline lifecycle + private Collection<PipelineLifecycleJob> lifecycleJobs = new ArrayList<PipelineLifecycleJob>(); + /** * Creates and initializes a new Pipeline. */ @@ -89,18 +91,14 @@ } /** - * Adds a [EMAIL PROTECTED] StageEventListener} to the pipline that will be notified by calls - * to [EMAIL PROTECTED] Stage#raise(StageEvent)}. - * @param listener The listener to be notified. + * [EMAIL PROTECTED] */ public void registerListener(StageEventListener listener) { listeners.add(listener); } /** - * Returns the collection of [EMAIL PROTECTED] StageEventListener}s registered with the - * context. - * @return The collection of registered listeners. + * [EMAIL PROTECTED] */ public Collection<StageEventListener> getRegisteredListeners() { return this.listeners; @@ -136,10 +134,7 @@ } /** - * This method is used by a stage driver to pass data from one stage to the next. - * @return the feeder for the downstream stage, or null if no downstream - * stage exists. - * @param stage the stage for which the downstream feeder will be retrieved + * [EMAIL PROTECTED] */ public Feeder getDownstreamFeeder(Stage stage) { if (stage == null) throw new IllegalArgumentException("Unable to look up downstream feeder for null stage."); @@ -158,23 +153,18 @@ } /** - * Look up and return the source feeder for the specified pipeline branch. - * @param branch the string identifier of the branch for which a feeder will be returned - * @return the feeder for the specified branch + * [EMAIL PROTECTED] */ public Feeder getBranchFeeder(String branch) { if (!getBranches().containsKey(branch)) { throw new IllegalStateException("Unable to find branch in pipeline: '" + branch + "'"); } - + return branches.get(branch).getSourceFeeder(); } /** - * Global environment accessor method. - * - * @return the global environment value corresponding to the specified - * key, or null if no such key is found. + * [EMAIL PROTECTED] */ public Object getEnv(String key) { return this.env.get(key); @@ -322,6 +312,13 @@ } /** + * Adds a job to be onStart on startup to the pipeline. + */ + public void addLifecycleJob(PipelineLifecycleJob job) { + this.lifecycleJobs.add(job); + } + + /** * This method iterates over the stages in the pipeline, looking up a * [EMAIL PROTECTED] StageDriver} for each stage and using that driver to start the stage. * Startups may occur sequentially or in parallel, depending upon the stage driver @@ -331,6 +328,7 @@ * @throws org.apache.commons.pipeline.StageException Thrown if there is an error during pipeline startup */ public void start() throws StageException { + for (PipelineLifecycleJob job : lifecycleJobs) job.onStart(this); for (StageDriver driver: this.drivers) driver.start(); for (Pipeline branch : branches.values()) branch.start(); } @@ -346,13 +344,9 @@ * @throws org.apache.commons.pipeline.StageException Thrown if there is an unhandled error during stage shutdown */ public void finish() throws StageException { - for (StageDriver driver: this.drivers){ - driver.finish(); - } - - for (Pipeline pipeline : branches.values()) { - pipeline.finish(); - } + for (StageDriver driver: this.drivers) driver.finish(); + for (Pipeline pipeline : branches.values()) pipeline.finish(); + for (PipelineLifecycleJob job : lifecycleJobs) job.onFinish(this); } /** @@ -384,7 +378,7 @@ public void setValidator(PipelineValidator validator) { this.validator = validator; } - + /** * Returns the parent of this pipeline, if it is a branch * @return parent Pipeline, or null if this is the main pipeline Added: commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/PipelineLifecycleJob.java URL: http://svn.apache.org/viewvc/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/PipelineLifecycleJob.java?view=auto&rev=562531 ============================================================================== --- commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/PipelineLifecycleJob.java (added) +++ commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/PipelineLifecycleJob.java Fri Aug 3 10:51:49 2007 @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.pipeline; + +/** + * This interface specifies a job or set of tasks that are to be run at a + * well-specified points in the pipeline lifecycle. It is intended to be a + * means by which third-party plugins can be added to the pipeline framework. + */ +public interface PipelineLifecycleJob { + + /** + * This is called by the pipeline engine once the pipeline is fully configured, + * just prior to stage driver start. + */ + public void onStart(Pipeline pipeline); + + /** + * This is called by the pipeline engine after all data processing has completed. + */ + public void onFinish(Pipeline pipeline); + +} Propchange: commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/PipelineLifecycleJob.java ------------------------------------------------------------------------------ svn:eol-style = native