You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2008/11/05 19:50:12 UTC
svn commit: r711655 - in /activemq/camel/trunk:
camel-core/src/main/java/org/apache/camel/model/
camel-core/src/test/java/org/apache/camel/processor/aggregator/
components/camel-spring/src/test/java/org/apache/camel/spring/processor/
components/camel-s...
Author: janstey
Date: Wed Nov 5 10:50:12 2008
New Revision: 711655
URL: http://svn.apache.org/viewvc?rev=711655&view=rev
Log:
CAMEL-1038 - add support for a custom aggregation collection in the Spring DSL
Added:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/MyReverseAggregationCollection.java (with props)
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAggregatorWithCustomCollectionTest.java (with props)
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator-custom-collection.xml (with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/CustomAggregationCollectionTest.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java?rev=711655&r1=711654&r2=711655&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AggregatorType.java Wed Nov 5 10:50:12 2008
@@ -59,6 +59,8 @@
private Long batchTimeout;
@XmlAttribute(required = false)
private String strategyRef;
+ @XmlAttribute(required = false)
+ private String collectionRef;
@XmlElement(name = "completedPredicate", required = false)
private ExpressionSubElementType completedPredicate;
@@ -121,6 +123,10 @@
final Processor processor = routeContext.createProcessor(this);
final Aggregator aggregator;
+ if (getAggregationCollection() == null) {
+ setAggregationCollection(createAggregationCollection(routeContext));
+ }
+
if (aggregationCollection != null) {
// create the aggregator using the collection
// pre configure the collection if its expression and strategy is not set, then
@@ -177,6 +183,14 @@
return strategy;
}
+ private AggregationCollection createAggregationCollection(RouteContext routeContext) {
+ AggregationCollection collection = getAggregationCollection();
+ if (collection == null && collectionRef != null) {
+ collection = routeContext.lookup(collectionRef, AggregationCollection.class);
+ }
+ return collection;
+ }
+
public AggregationCollection getAggregationCollection() {
return aggregationCollection;
}
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/CustomAggregationCollectionTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/CustomAggregationCollectionTest.java?rev=711655&r1=711654&r2=711655&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/CustomAggregationCollectionTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/CustomAggregationCollectionTest.java Wed Nov 5 10:50:12 2008
@@ -71,52 +71,4 @@
}
};
}
-
- // START SNIPPET: e3
- private static class MyReverseAggregationCollection extends AbstractCollection<Exchange> implements AggregationCollection {
-
- private List<Exchange> collection = new ArrayList<Exchange>();
- private Expression correlation;
- private AggregationStrategy strategy;
-
- public Expression getCorrelationExpression() {
- return correlation;
- }
-
- public void setCorrelationExpression(Expression correlationExpression) {
- this.correlation = correlationExpression;
- }
-
- public AggregationStrategy getAggregationStrategy() {
- return strategy;
- }
-
- public void setAggregationStrategy(AggregationStrategy aggregationStrategy) {
- this.strategy = aggregationStrategy;
- }
-
- public boolean add(Exchange exchange) {
- return collection.add(exchange);
- }
-
- public Iterator<Exchange> iterator() {
- // demonstrate the we can do something with this collection, so we reverse it
- Collections.reverse(collection);
-
- return collection.iterator();
- }
-
- public int size() {
- return collection.size();
- }
-
- public void clear() {
- collection.clear();
- }
-
- public void onAggregation(Object correlationKey, Exchange newExchange) {
- add(newExchange);
- }
- }
- // END SNIPPET: e3
}
\ No newline at end of file
Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/MyReverseAggregationCollection.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/MyReverseAggregationCollection.java?rev=711655&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/MyReverseAggregationCollection.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/MyReverseAggregationCollection.java Wed Nov 5 10:50:12 2008
@@ -0,0 +1,75 @@
+/**
+ * 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.camel.processor.aggregator;
+
+import java.util.AbstractCollection;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.processor.aggregate.AggregationCollection;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+
+class MyReverseAggregationCollection extends AbstractCollection<Exchange> implements AggregationCollection {
+
+ private List<Exchange> collection = new ArrayList<Exchange>();
+ private Expression correlation;
+ private AggregationStrategy strategy;
+
+ public Expression getCorrelationExpression() {
+ return correlation;
+ }
+
+ public void setCorrelationExpression(Expression correlationExpression) {
+ this.correlation = correlationExpression;
+ }
+
+ public AggregationStrategy getAggregationStrategy() {
+ return strategy;
+ }
+
+ public void setAggregationStrategy(AggregationStrategy aggregationStrategy) {
+ this.strategy = aggregationStrategy;
+ }
+
+ public boolean add(Exchange exchange) {
+ return collection.add(exchange);
+ }
+
+ public Iterator<Exchange> iterator() {
+ // demonstrate the we can do something with this collection, so we reverse it
+ Collections.reverse(collection);
+
+ return collection.iterator();
+ }
+
+ public int size() {
+ return collection.size();
+ }
+
+ public void clear() {
+ collection.clear();
+ }
+
+ public void onAggregation(Object correlationKey, Exchange newExchange) {
+ add(newExchange);
+ }
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/MyReverseAggregationCollection.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAggregatorWithCustomCollectionTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAggregatorWithCustomCollectionTest.java?rev=711655&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAggregatorWithCustomCollectionTest.java (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAggregatorWithCustomCollectionTest.java Wed Nov 5 10:50:12 2008
@@ -0,0 +1,30 @@
+/**
+ * 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.camel.spring.processor;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.processor.aggregator.CustomAggregationCollectionTest;
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+/**
+ * @version $Revision: 630591 $
+ */
+public class SpringAggregatorWithCustomCollectionTest extends CustomAggregationCollectionTest {
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this, "org/apache/camel/spring/processor/aggregator-custom-collection.xml");
+ }
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAggregatorWithCustomCollectionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator-custom-collection.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator-custom-collection.xml?rev=711655&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator-custom-collection.xml (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator-custom-collection.xml Wed Nov 5 10:50:12 2008
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- START SNIPPET: example -->
+ <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <aggregator batchTimeout="500" collectionRef="aggregatorCollection">
+ <expression/>
+ <to uri="mock:result"/>
+ </aggregator>
+ </route>
+ </camelContext>
+
+ <bean id="aggregatorCollection" class="org.apache.camel.processor.aggregator.MyReverseAggregationCollection"/>
+ <!-- END SNIPPET: example -->
+</beans>
Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator-custom-collection.xml
------------------------------------------------------------------------------
svn:eol-style = native