commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nutty...@apache.org
Subject svn commit: r465019 - in /jakarta/commons/sandbox/pipeline/trunk/src: main/java/org/apache/commons/pipeline/ main/java/org/apache/commons/pipeline/config/ main/java/org/apache/commons/pipeline/testFramework/ test/java/org/apache/commons/pipeline/config...
Date Tue, 17 Oct 2006 19:55:55 GMT
Author: nuttycom
Date: Tue Oct 17 12:55:53 2006
New Revision: 465019

URL: http://svn.apache.org/viewvc?view=rev&rev=465019
Log:
Added global environment variables to StageContext.

Modified:
    jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/Pipeline.java
    jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/StageContext.java
    jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/config/PipelineRuleSet.java
    jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/testFramework/TestStageContext.java
    jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/config/DigesterPipelineFactoryTest.java
    jakarta/commons/sandbox/pipeline/trunk/src/test/resources/TestResources.properties
    jakarta/commons/sandbox/pipeline/trunk/src/test/resources/test_conf.xml

Modified: jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/Pipeline.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/Pipeline.java?view=diff&rev=465019&r1=465018&r2=465019
==============================================================================
--- jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/Pipeline.java
(original)
+++ jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/Pipeline.java
Tue Oct 17 12:55:53 2006
@@ -73,6 +73,9 @@
     // Feeder used to handle output of final stage
     private Feeder terminalFeeder = Feeder.VOID;
     
+    // Global environment variables
+    private Map<String,Object> env = Collections.synchronizedMap(new HashMap<String,Object>());
+            
     /**
      * Creates and initializes a new Pipeline.
      */
@@ -164,6 +167,23 @@
         }
 
         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.
+     */
+    public Object getEnv(String key) {
+        return this.env.get(key);
+    }
+    
+    /**
+     * Sets the value corresponding to the specified environment variable key.
+     */
+    public void setEnv(String key, Object value) {
+        this.env.put(key, value);
     }
     
     /**

Modified: jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/StageContext.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/StageContext.java?view=diff&rev=465019&r1=465018&r2=465019
==============================================================================
--- jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/StageContext.java
(original)
+++ jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/StageContext.java
Tue Oct 17 12:55:53 2006
@@ -59,11 +59,21 @@
     
     /**
      * This method is used by a stage driver to pass data from one stage to the next.
-     * @returns the feeder for the downstream stage, or {@link Feeder#VOID} if no downstream
+     * @return the feeder for the downstream stage, or {@link Feeder#VOID} if no downstream
      * stage exists.
      * @param stage The stage from which "downstream" will be determined. Ordinarily a Stage
implementation
      * will call this method with a reference to itself.
      * @return The {@link Feeder} for the subsequent stage.
      */
     public Feeder getDownstreamFeeder(Stage stage);
+    
+    /**
+     * A StageContext implementation provides a global environment for the
+     * stages being run. This method allows objects in the global environment
+     * to be accessed by the stages running in this context.
+     *
+     * @return the object corresponding to the specified string key, or null
+     * if no such key exists.
+     */
+    public Object getEnv(String key);
 }

Modified: jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/config/PipelineRuleSet.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/config/PipelineRuleSet.java?view=diff&rev=465019&r1=465018&r2=465019
==============================================================================
--- jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/config/PipelineRuleSet.java
(original)
+++ jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/config/PipelineRuleSet.java
Tue Oct 17 12:55:53 2006
@@ -94,6 +94,7 @@
  */
 public class PipelineRuleSet extends RuleSetBase {
     private static Class[] addBranchTypes = { String.class, Pipeline.class };
+    private static Class[] setEnvTypes = { String.class, Object.class };
     private List<RuleSet> nestedRuleSets;
     
     /**
@@ -128,12 +129,23 @@
         digester.addSetProperties("pipeline");
         digester.addRule("pipeline", new PipelineDriverFactoriesRule());
                 
-        // these rules are used to add subchains to the main pipeline
+        //these rules are used to add branches to the main pipeline
         digester.addFactoryCreate("*/branch/pipeline", pipelineFactory);
         digester.addRule("*/branch/pipeline", new CallMethodRule(1, "addBranch", 2, addBranchTypes));
         digester.addCallParam("*/branch/pipeline", 0, "key");
         digester.addCallParam("*/branch/pipeline", 1, 0);
         digester.addRule("*/branch/pipeline", new PipelineDriverFactoriesRule());
+        
+        //rules for adding values to the global pipeline environment        
+        digester.addObjectCreate("*/pipeline/env/object", "java.lang.Object", "className");
       
+        digester.addSetProperties("*/pipeline/env/object");
+        digester.addRule("*/pipeline/env/object", new CallMethodRule(1, "setEnv", 2, setEnvTypes));
+        digester.addCallParam("*/pipeline/env/object", 0, "key");
+        digester.addCallParam("*/pipeline/env/object", 1, 0);
+        
+        digester.addRule("*/pipeline/env/value", new CallMethodRule(0, "setEnv", 2, setEnvTypes));
+        digester.addCallParam("*/pipeline/env/value", 0, "key");
+        digester.addCallParam("*/pipeline/env/value", 1);
         
         //this rule is intended to be used to add a StageEventListener to the pipeline.
         digester.addObjectCreate("*/pipeline/listener", "org.apache.commons.pipeline.StageEventListener",
"className");

Modified: jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/testFramework/TestStageContext.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/testFramework/TestStageContext.java?view=diff&rev=465019&r1=465018&r2=465019
==============================================================================
--- jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/testFramework/TestStageContext.java
(original)
+++ jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/testFramework/TestStageContext.java
Tue Oct 17 12:55:53 2006
@@ -33,6 +33,7 @@
     public List<EventObject> raisedEvents = new ArrayList<EventObject>();
     public Map<String, TestFeeder> branchFeeders = new HashMap<String,TestFeeder>();
     public Map<Stage, Feeder> downstreamFeeders = new HashMap<Stage,Feeder>();
+    public Map<String, Object> env = new HashMap<String, Object>();
     
     public void registerListener(StageEventListener listener) {
         this.listeners.add(listener);
@@ -81,4 +82,15 @@
     public Collection<StageEventListener> getRegisteredListeners() {
         return this.listeners;
     }
+
+    /**
+     * This method allows objects in the global environment
+     * to be accessed by the stages running in this context.
+     * 
+     * @return the object corresponding to the specified string key, or null
+     * if no such key exists.
+     */
+    public Object getEnv(String key) {
+        return this.env.get(key);
+    }    
 }

Modified: jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/config/DigesterPipelineFactoryTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/config/DigesterPipelineFactoryTest.java?view=diff&rev=465019&r1=465018&r2=465019
==============================================================================
--- jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/config/DigesterPipelineFactoryTest.java
(original)
+++ jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/config/DigesterPipelineFactoryTest.java
Tue Oct 17 12:55:53 2006
@@ -38,28 +38,28 @@
         super(testName);
     }
     
-    public static junit.framework.Test suite() {        
+    public static junit.framework.Test suite() {
         junit.framework.TestSuite suite = new junit.framework.TestSuite(DigesterPipelineFactoryTest.class);
         
         return suite;
-    }    
+    }
     
     public void testCreatePipeline() throws Exception {
         Log log = LogFactory.getLog(this.getClass());
         URL confURL = this.getClass().getClassLoader().getResource(testResources.getString(keyBase
+ ".configFile"));
         PipelineFactory factory = new DigesterPipelineFactory(confURL);
-            
-            Pipeline pipeline = factory.createPipeline();
+        
+        Pipeline pipeline = factory.createPipeline();
         assertNotNull("Pipeline exists.", pipeline);
-            
-            int i = 0;
+        
+        int i = 0;
         for (Stage stage : pipeline.getStages()) {
             assertNotNull("Stage is not null.", stage);
             assertEquals(stage.getClass(), Class.forName(testResources.getString(keyBase
+ ".stage" + i + ".class")));
-                i++;
-            }
-            
-            pipeline.run();
+            i++;
+        }
+        
+        pipeline.run();
         
         boolean eventsRecorded = false;
         assertTrue("Pipeline has at least one listener.", pipeline.getRegisteredListeners().size()
> 0);
@@ -68,8 +68,11 @@
                 log.info(((ObjectProcessedEventCounter) l).getCounts().size() + " event sources
found.");
                 assertTrue("Events were recorded by the ObjectProcessedEventListener.", ((ObjectProcessedEventCounter)
l).getCounts().size() > 0);
                 eventsRecorded = true;
-        }
+            }
         }
         assertTrue("Events were raised and properly recorded by the listener.", eventsRecorded);
+        
+        assertNotNull(pipeline.getEnv("testDate"));
+        assertEquals("Hello, World!", pipeline.getEnv("testEnvVar"));
     }
 }

Modified: jakarta/commons/sandbox/pipeline/trunk/src/test/resources/TestResources.properties
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/pipeline/trunk/src/test/resources/TestResources.properties?view=diff&rev=465019&r1=465018&r2=465019
==============================================================================
--- jakarta/commons/sandbox/pipeline/trunk/src/test/resources/TestResources.properties (original)
+++ jakarta/commons/sandbox/pipeline/trunk/src/test/resources/TestResources.properties Tue
Oct 17 12:55:53 2006
@@ -19,3 +19,4 @@
 test.DigesterPipelineFactoryTest.stage0.class=org.apache.commons.pipeline.stage.FileFinderStage
 test.DigesterPipelineFactoryTest.stage1.class=org.apache.commons.pipeline.stage.LogStage
 test.DigesterPipelineFactoryTest.stage2.class=org.apache.commons.pipeline.stage.RaiseEventStage
+test.DigesterPipelineFactoryTest.stage3.class=org.apache.commons.pipeline.stage.RaiseKeyAvailableEventStage

Modified: jakarta/commons/sandbox/pipeline/trunk/src/test/resources/test_conf.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/pipeline/trunk/src/test/resources/test_conf.xml?view=diff&rev=465019&r1=465018&r2=465019
==============================================================================
--- jakarta/commons/sandbox/pipeline/trunk/src/test/resources/test_conf.xml (original)
+++ jakarta/commons/sandbox/pipeline/trunk/src/test/resources/test_conf.xml Tue Oct 17 12:55:53
2006
@@ -21,6 +21,10 @@
 <pipeline>
   <listener className="org.apache.commons.pipeline.listener.ObjectProcessedEventCounter"/>
   <driverFactory className="org.apache.commons.pipeline.driver.DedicatedThreadStageDriverFactory"
id="f1"/>
+  <env>
+      <object className="java.util.Date" key="testDate"/>
+      <value key="testEnvVar">Hello, World!</value>
+  </env>
 
   <stage className="org.apache.commons.pipeline.stage.FileFinderStage" driverFactoryId="f1"
          filePattern=".*\.java" />
@@ -28,6 +32,11 @@
   <stage className="org.apache.commons.pipeline.stage.LogStage" driverFactoryId="f1" />
                    
   <stage className="org.apache.commons.pipeline.stage.RaiseEventStage" driverFactoryId="f1"
/>
+  
+  <!--
+  <stage className="org.apache.commons.pipeline.stage.RaiseKeyAvailableEventStage" driverFactoryId="f1"

+         keyFactoryClass="org.apache.commons.pipeline.opt.KeyFactory$HashKeyFactory"/>
+  -->
   
   <feed>
     <value>src/main/java</value>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message