You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by nu...@apache.org on 2006/10/26 23:47:56 UTC
svn commit: r468154 - in /jakarta/commons/sandbox/pipeline/trunk/src:
main/java/org/apache/commons/pipeline/config/
test/java/org/apache/commons/pipeline/config/ test/resources/
Author: nuttycom
Date: Thu Oct 26 14:47:55 2006
New Revision: 468154
URL: http://svn.apache.org/viewvc?view=rev&rev=468154
Log:
Updated Digester configuration system & tests to encompass new features
Modified:
jakarta/commons/sandbox/pipeline/trunk/src/main/java/org/apache/commons/pipeline/config/PipelineRuleSet.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/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=468154&r1=468153&r2=468154
==============================================================================
--- 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 Thu Oct 26 14:47:55 2006
@@ -1,24 +1,28 @@
/*
- * Copyright 2005 The Apache Software Foundation
- *
- * Licensed 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
+ * 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.
- */
+ * 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.config;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.digester.*;
import org.apache.commons.pipeline.*;
import org.xml.sax.Attributes;
@@ -31,15 +35,15 @@
* <ul>
* <li>
* <code><pipeline></pipeline></code><br/>
- * The root element of the XML configuration file for a pipeline. This tag
- * supports two optional attributes that are for use only when configuring
- * branch pipelines, <code>key</code> and <code>configURI</code>. These
+ * The root element of the XML configuration file for a pipeline. This tag
+ * supports two optional attributes that are for use only when configuring
+ * branch pipelines, <code>key</code> and <code>configURI</code>. These
* attributes are described more fully below in the <code><branch></code>
* documentation.
- * </li>
+ * </li>
* <li>
* <code><driverFactory className="<em>MyDriverFactory</em>" id="<em>my_id</em>" ... /></code><br/>
- * This tag is used to create and configure a {@link StageDriverFactory} that
+ * This tag is used to create and configure a {@link StageDriverFactory} that
* will be used to create {@link StageDriver} instances for stages
* in the parent pipeline. Each {@link StageDriverFactory} is identified by a unique
* string identifier that is used by the <code><stage></code> tag
@@ -51,40 +55,40 @@
* </li>
* <li>
* <code><stage className="<em>MyStageClass</em>" driverFactoryId="<i>name</i>" ... ></stage></code><br/>
- * A single stage is created, configured, and added to the parent pipeline using
- * this tag. Stages created in this manner are added to the pipeline in the order
+ * A single stage is created, configured, and added to the parent pipeline using
+ * this tag. Stages created in this manner are added to the pipeline in the order
* that they occur in the configuration file. The class of the stage (which must
* provide a no-argument constructor) is specified by the <em>className</em> attribute.
* Each stage should be associated with a previously declared driver factory
- * by use of the <code>driverFactoryId</code> attribute. All other attributes are
- * used by Digester to set bean properties on the newly created Stage object.
+ * by use of the <code>driverFactoryId</code> attribute. All other attributes are
+ * used by Digester to set bean properties on the newly created Stage object.
* </li>
* <li>
* <code><feed/></code><br/>
- * Enqueue an object onto the first stage in the pipeline. There are two
+ * Enqueue an object onto the first stage in the pipeline. There are two
* types of usage available, provided by the following subtags:
* <ul>
* <li>
* <code><value>my_value</value></code><br/>
* Feed the string value of the body of this tag to the first stage in the
- * pipeline.
+ * pipeline.
* </li>
* <li>
* <code><object className="MyClass" ... /></code><br/>
* This tag uses the standard Digester ObjectCreateRule to create an
* arbitrary object of the specified class (which must provide a
* no-argument constructor) to the first stage in the pipeline.
- * All attributes other than <code>className</codee> are used by
+ * All attributes other than <code>className</codee> are used by
* Digester to set bean properties on the newly created object.
- * </li>
+ * </li>
* </ul>
* </li>
* <li>
* <code><branch/></code><br/>
* Add a branch to a pipeline. The contents of this tag should
- * be one or more <code><pipeline/></code> declarations. Branch
- * pipelines added in this fashion must be configured with an attribute
- * named <code>key</code> that holds the name by which the branch pipeline
+ * be one or more <code><pipeline/></code> declarations. Branch
+ * pipelines added in this fashion must be configured with an attribute
+ * named <code>key</code> that holds the name by which the branch pipeline
* will be referred to.<br/>
* Branch pipelines may be configured either inline in the main configuration
* file or in a separate file referred to by the <code>configURI</code> pipeline
@@ -106,7 +110,7 @@
/**
* Creates a new pipeline rule set with the specified collection of additional
* rule sets that may be used for recursive creation of branch pipelines.
- * @param nestedRuleSets A list of other RuleSet instances that are being used in conjunction with the
+ * @param nestedRuleSets A list of other RuleSet instances that are being used in conjunction with the
* PipelineRuleSet. In the case that branch pipelines are referred to by URI, these
* rule sets will be added to a new Digester instance (along with a PipelineRuleSet
* instance) that is used to parse the branch configuration file.
@@ -128,7 +132,7 @@
digester.addFactoryCreate("pipeline", pipelineFactory);
digester.addSetProperties("pipeline");
digester.addRule("pipeline", new PipelineDriverFactoriesRule());
-
+
//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));
@@ -136,8 +140,8 @@
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");
+ //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");
@@ -156,6 +160,16 @@
digester.addFactoryCreate("*/pipeline/driverFactory", driverFactoryFactory);
digester.addSetProperties("*/pipeline/driverFactory");
+ digester.addObjectCreate("*/driverFactory", "org.apache.commons.pipeline.StageDriverFactory", "className");
+ digester.addSetProperties("*/driverFactory");
+ digester.addSetNext("*/driverFactory", "setWrappedSDF", "org.apache.commons.pipeline.StageDriverFactory");
+
+ //rules for setting an object property on the next-to-top object on the stack
+ //similar to setNestedPropertiesRule
+ digester.addObjectCreate("*/property", "java.lang.Object", "className");
+ digester.addSetProperties("*/property");
+ digester.addRule("*/property", new SetNestedPropertyObjectRule());
+
//this rule is intended to be used to add a stage to a pipeline
digester.addObjectCreate("*/pipeline/stage", "org.apache.commons.pipeline.BaseStage", "className");
digester.addSetProperties("*/pipeline/stage");
@@ -169,13 +183,13 @@
digester.addSetProperties("*/pipeline/feed/object");
digester.addRule("*/pipeline/feed/object", new PipelineFeedObjectRule());
}
-
+
/**
* This factory is used to create a pipeline. If the "configURI" parameter
* is specified, the pipeline is created based upon the configuration file
* located at that URI.
*/
- private class PipelineFactory extends AbstractObjectCreationFactory {
+ private class PipelineFactory extends AbstractObjectCreationFactory {
public Object createObject(Attributes attributes) throws java.lang.Exception {
String configURI = attributes.getValue("configURI");
if (configURI == null) {
@@ -204,13 +218,30 @@
digester.push("org.apache.commons.pipeline.config.DriverFactories", new HashMap<String, StageDriverFactory>());
super.begin(namespace, name, attributes);
}
-
+
public void end(String namespace, String name) throws Exception {
super.end(namespace, name);
digester.pop("org.apache.commons.pipeline.config.DriverFactories");
}
}
-
+
+ /**
+ * Configure the storage for the map of driver factories for the pipeline.
+ */
+ private class SetNestedPropertyObjectRule extends Rule {
+ String propName;
+
+ public void begin(String namespace, String name, Attributes attributes) throws Exception {
+ propName = attributes.getValue("propName");
+ super.begin(namespace, name, attributes);
+ }
+
+ public void end(String namespace, String name) throws Exception {
+ super.end(namespace, name);
+ BeanUtils.setProperty(digester.peek(1), propName, digester.peek());
+ }
+ }
+
/**
* This ObjectCreationFactory creates a stage driver factory and stores
* it in the scope of the rule set so that it can be retrieved by the stage
@@ -254,8 +285,8 @@
Pipeline pipeline = (Pipeline) digester.peek(1);
pipeline.addStage(stage, factory);
}
- }
-
+ }
+
/**
* This Rule allows an object to be fed to the pipeline.
*/
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=468154&r1=468153&r2=468154
==============================================================================
--- 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 Thu Oct 26 14:47:55 2006
@@ -1,18 +1,21 @@
/*
- * Copyright 2005 The Apache Software Foundation
- *
- * Licensed 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
- *
+ * 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.
- */
+ *
+ * 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.config;
@@ -26,6 +29,9 @@
import org.apache.commons.pipeline.Stage;
import org.apache.commons.pipeline.StageEventListener;
import org.apache.commons.pipeline.listener.ObjectProcessedEventCounter;
+import org.apache.commons.pipeline.stage.KeyWaitBufferStage;
+import org.apache.commons.pipeline.testFramework.TestFeeder;
+import org.apache.commons.pipeline.util.BlockingQueueFactory;
/**
* Test cases for the DigesterPipelineFactory.
@@ -50,6 +56,8 @@
PipelineFactory factory = new DigesterPipelineFactory(confURL);
Pipeline pipeline = factory.createPipeline();
+ TestFeeder terminalFeeder = new TestFeeder();
+ pipeline.setTerminalFeeder(terminalFeeder);
assertNotNull("Pipeline exists.", pipeline);
int i = 0;
@@ -57,10 +65,14 @@
assertNotNull("Stage is not null.", stage);
assertEquals(stage.getClass(), Class.forName(testResources.getString(keyBase + ".stage" + i + ".class")));
i++;
+ if (stage instanceof KeyWaitBufferStage) {
+ assertTrue(((KeyWaitBufferStage) stage).getQueueFactory() instanceof BlockingQueueFactory.ArrayBlockingQueueFactory);
+ }
}
pipeline.run();
+
boolean eventsRecorded = false;
assertTrue("Pipeline has at least one listener.", pipeline.getRegisteredListeners().size() > 0);
for (StageEventListener l : pipeline.getRegisteredListeners()) {
@@ -74,5 +86,6 @@
assertNotNull(pipeline.getEnv("testDate"));
assertEquals("Hello, World!", pipeline.getEnv("testEnvVar"));
+ assertTrue("Terminal feeder did not receive any data.", terminalFeeder.receivedValues.size() > 0);
}
}
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=468154&r1=468153&r2=468154
==============================================================================
--- jakarta/commons/sandbox/pipeline/trunk/src/test/resources/TestResources.properties (original)
+++ jakarta/commons/sandbox/pipeline/trunk/src/test/resources/TestResources.properties Thu Oct 26 14:47:55 2006
@@ -20,3 +20,5 @@
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
+test.DigesterPipelineFactoryTest.stage4.class=org.apache.commons.pipeline.stage.KeyWaitBufferStage
+test.DigesterPipelineFactoryTest.stage5.class=org.apache.commons.pipeline.stage.LogStage
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=468154&r1=468153&r2=468154
==============================================================================
--- jakarta/commons/sandbox/pipeline/trunk/src/test/resources/test_conf.xml (original)
+++ jakarta/commons/sandbox/pipeline/trunk/src/test/resources/test_conf.xml Thu Oct 26 14:47:55 2006
@@ -14,13 +14,16 @@
* 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.
- *
- * Author : Kris Nuttycombe, National Geophysical Data Center
-->
<pipeline>
<listener className="org.apache.commons.pipeline.listener.ObjectProcessedEventCounter"/>
- <driverFactory className="org.apache.commons.pipeline.driver.DedicatedThreadStageDriverFactory" id="f1"/>
+
+ <driverFactory className="org.apache.commons.pipeline.driver.DedicatedThreadStageDriverFactory" id="f1">
+ <property propName="queueFactory" className="org.apache.commons.pipeline.util.BlockingQueueFactory$ArrayBlockingQueueFactory"
+ capacity="10" fair="false"/>
+ </driverFactory>
+
<env>
<object className="java.util.Date" key="testDate"/>
<value key="testEnvVar">Hello, World!</value>
@@ -28,18 +31,25 @@
<stage className="org.apache.commons.pipeline.stage.FileFinderStage" driverFactoryId="f1"
filePattern=".*\.java" />
-
- <stage className="org.apache.commons.pipeline.stage.LogStage" driverFactoryId="f1" />
+ <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"/>
- -->
+ <stage className="org.apache.commons.pipeline.stage.RaiseKeyAvailableEventStage" driverFactoryId="f1">
+ <property propName="keyFactory" className="org.apache.commons.pipeline.util.KeyFactory$HashKeyFactory"/>
+ </stage>
+
+ <stage className="org.apache.commons.pipeline.stage.KeyWaitBufferStage" driverFactoryId="f1">
+ <property propName="keyFactory" className="org.apache.commons.pipeline.util.KeyFactory$HashKeyFactory"/>
+ <property propName="queueFactory" className="org.apache.commons.pipeline.util.BlockingQueueFactory$ArrayBlockingQueueFactory"
+ capacity="10" fair="false"/>
+ </stage>
+ <stage className="org.apache.commons.pipeline.stage.LogStage" driverFactoryId="f1" />
+
<feed>
<value>src/main/java</value>
- <value>src/test/java</value>
+ <value>src/test/java</value>
</feed>
</pipeline>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org