activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r519943 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/builder/ test/java/org/apache/camel/
Date Mon, 19 Mar 2007 13:38:19 GMT
Author: jstrachan
Date: Mon Mar 19 06:38:18 2007
New Revision: 519943

URL: http://svn.apache.org/viewvc?view=rev&rev=519943
Log:
added the ability to add custom processors to the DSL

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ConstantProcessorBuilder.java
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ConfiguredDestinationBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DestinationBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ProcessorBuilder.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/RouteBuilderTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ConfiguredDestinationBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ConfiguredDestinationBuilder.java?view=diff&rev=519943&r1=519942&r2=519943
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ConfiguredDestinationBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ConfiguredDestinationBuilder.java
Mon Mar 19 06:38:18 2007
@@ -37,9 +37,4 @@
     public Processor<E> createProcessor() {
         return new SendProcessor<E>(destination);
     }
-
-    @Override
-    public void createProcessors() {
-        getParent().addProcessor(new SendProcessor<E>(destination));
-    }
 }

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ConstantProcessorBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ConstantProcessorBuilder.java?view=auto&rev=519943
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ConstantProcessorBuilder.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ConstantProcessorBuilder.java
Mon Mar 19 06:38:18 2007
@@ -0,0 +1,36 @@
+/**
+ *
+ * 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.builder;
+
+import org.apache.camel.Processor;
+import org.apache.camel.Exchange;
+
+/**
+ * @version $Revision$
+ */
+public class ConstantProcessorBuilder<E extends Exchange> implements ProcessorBuilder<E>
{
+    private Processor<E> processor;
+
+    public ConstantProcessorBuilder(Processor<E> processor) {
+        this.processor = processor;
+    }
+
+    public Processor<E> createProcessor() {
+        return processor;
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ConstantProcessorBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ConstantProcessorBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ConstantProcessorBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DestinationBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DestinationBuilder.java?view=diff&rev=519943&r1=519942&r2=519943
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DestinationBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DestinationBuilder.java
Mon Mar 19 06:38:18 2007
@@ -74,6 +74,18 @@
         return answer;
     }
 
+
+    /**
+     * Adds the custom processor to this destination
+     */
+    public ProcessorBuilder<E> process(Processor<E> processor) {
+        ConstantProcessorBuilder<E> answer = new ConstantProcessorBuilder<E>(processor);
+        addProcessBuilder(answer);
+        return answer;
+    }
+
+
+
     /**
      * Creates a predicate which is applied and only if it is true then
      * the exchange is forwarded to the destination
@@ -131,12 +143,6 @@
         }
         else {
             return new CompositeProcessor<E>(answer);
-        }
-    }
-
-    public void createProcessors() {
-        for (ProcessorBuilder<E> processBuilder : processBuilders) {
-            processBuilder.createProcessors();
         }
     }
 

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ProcessorBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ProcessorBuilder.java?view=diff&rev=519943&r1=519942&r2=519943
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ProcessorBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ProcessorBuilder.java
Mon Mar 19 06:38:18 2007
@@ -20,10 +20,11 @@
 import org.apache.camel.Processor;
 
 /**
+ * An interface representing a builder of a {@link Processor}
+ * 
  * @version $Revision$
  */
 public interface ProcessorBuilder<E extends Exchange> {
-    public void createProcessors();
 
     public Processor<E> createProcessor();
 

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/RouteBuilderTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/RouteBuilderTest.java?view=diff&rev=519943&r1=519942&r2=519943
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/RouteBuilderTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/RouteBuilderTest.java Mon
Mar 19 06:38:18 2007
@@ -27,6 +27,17 @@
  * @version $Revision$
  */
 public class RouteBuilderTest extends TestCase {
+    protected Processor<Exchange> myProcessor = new Processor<Exchange>() {
+        public void onExchange(Exchange exchange) {
+            System.out.println("Called with exchange: " + exchange);
+        }
+
+        @Override
+        public String toString() {
+            return "MyProcessor";
+        }
+    };
+
     public void testSimpleRoute() throws Exception {
         RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() {
             public void configure() {
@@ -105,12 +116,53 @@
             FilterProcessor<Exchange> filter2 = filters.get(1);
             assertSendTo(filter2.getProcessor(), "seda://c");
 
-
             assertSendTo(choiceProcessor.getOtherwise(), "seda://d");
         }
+    }
+
+    public void testCustomProcessor() throws Exception {
+        RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() {
+            public void configure() {
+                from("seda://a").process(myProcessor);
+            }
+        };
+
+        Map<Endpoint<Exchange>, Processor<Exchange>> routeMap = builder.getRouteMap();
+        System.out.println("Created map: " + routeMap);
+
+        Set<Map.Entry<Endpoint<Exchange>, Processor<Exchange>>> routes
= routeMap.entrySet();
+        assertEquals("Number routes created", 1, routes.size());
+        for (Map.Entry<Endpoint<Exchange>, Processor<Exchange>> route :
routes) {
+            Endpoint<Exchange> key = route.getKey();
+            assertEquals("From endpoint", "seda://a", key.getEndpointUri());
+            Processor processor = route.getValue();
 
+            assertEquals("Should be called with my processor", myProcessor, processor);
+        }
     }
 
+    public void testCustomProcessorWithFilter() throws Exception {
+        RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() {
+            public void configure() {
+                from("seda://a").filter(headerEquals("foo", "bar")).process(myProcessor);
+            }
+        };
+
+        Map<Endpoint<Exchange>, Processor<Exchange>> routeMap = builder.getRouteMap();
+        System.out.println("Created map: " + routeMap);
+
+        Set<Map.Entry<Endpoint<Exchange>, Processor<Exchange>>> routes
= routeMap.entrySet();
+        assertEquals("Number routes created", 1, routes.size());
+        for (Map.Entry<Endpoint<Exchange>, Processor<Exchange>> route :
routes) {
+            Endpoint<Exchange> key = route.getKey();
+            assertEquals("From endpoint", "seda://a", key.getEndpointUri());
+            Processor processor = route.getValue();
+
+            assertTrue("Processor should be a FilterProcessor but was: " + processor + "
with type: " + processor.getClass().getName(), processor instanceof FilterProcessor);
+            FilterProcessor filterProcessor = (FilterProcessor) processor;
+            assertEquals("Should be called with my processor", myProcessor, filterProcessor.getProcessor());
+        }
+    }
 
     protected void assertSendTo(Processor processor, String uri) {
         assertTrue("Processor should be a SendProcessor but was: " + processor + " with type:
" + processor.getClass().getName(), processor instanceof SendProcessor);



Mime
View raw message