activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r520962 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/builder/ test/java/org/apache/camel/builder/
Date Wed, 21 Mar 2007 17:45:39 GMT
Author: jstrachan
Date: Wed Mar 21 10:45:38 2007
New Revision: 520962

URL: http://svn.apache.org/viewvc?view=rev&rev=520962
Log:
added the ability to enable/disable the inheritence of error handlers so that we could, say,
use a single Dead Letter Channel on the top most Processor in a route

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java?view=diff&rev=520962&r1=520961&r2=520962
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
Wed Mar 21 10:45:38 2007
@@ -35,6 +35,7 @@
 public abstract class BuilderSupport<E extends Exchange> {
     private CamelContext context;
     private ErrorHandlerBuilder<E> errorHandlerBuilder;
+    private boolean inheritErrorHandler = true;
 
     protected BuilderSupport(CamelContext context) {
         this.context = context;
@@ -42,7 +43,8 @@
 
     protected BuilderSupport(BuilderSupport<E> parent) {
         this.context = parent.getContext();
-        if (parent.errorHandlerBuilder != null) {
+        this.inheritErrorHandler = parent.inheritErrorHandler;
+        if (inheritErrorHandler && parent.errorHandlerBuilder != null) {
             this.errorHandlerBuilder = parent.errorHandlerBuilder.copy();
         }
     }
@@ -181,11 +183,20 @@
 
     public ErrorHandlerBuilder<E> getErrorHandlerBuilder() {
         if (errorHandlerBuilder == null) {
-            errorHandlerBuilder = new DeadLetterChannelBuilder<E>();
+            errorHandlerBuilder = createErrorHandlerBuilder();
         }
         return errorHandlerBuilder;
     }
 
+    protected ErrorHandlerBuilder<E> createErrorHandlerBuilder() {
+        if (isInheritErrorHandler()) {
+            return new DeadLetterChannelBuilder<E>();
+        }
+        else {
+            return new NoErrorHandlerBuilder<E>();
+        }
+    }
+
     /**
      * Sets the error handler to use with processors created by this builder
      */
@@ -193,4 +204,11 @@
         this.errorHandlerBuilder = errorHandlerBuilder;
     }
 
+    public boolean isInheritErrorHandler() {
+        return inheritErrorHandler;
+    }
+
+    public void setInheritErrorHandler(boolean inheritErrorHandler) {
+        this.inheritErrorHandler = inheritErrorHandler;
+    }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java?view=diff&rev=520962&r1=520961&r2=520962
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
Wed Mar 21 10:45:38 2007
@@ -179,6 +179,18 @@
         return this;
     }
 
+    /**
+     * Configures whether or not the error handler is inherited by every processing node
(or just the top most one)
+     *
+     * @param value the falg as to whether error handlers should be inherited or not
+     * @return the current builder
+     */
+    public FromBuilder<E> inheritErrorHandler(boolean value) {
+        setInheritErrorHandler(value);
+        return this;
+    }
+
+
     // Properties
     //-------------------------------------------------------------------------
     public RouteBuilder<E> getBuilder() {

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java?view=diff&rev=520962&r1=520961&r2=520962
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
Wed Mar 21 10:45:38 2007
@@ -21,6 +21,7 @@
 import org.apache.camel.EndpointResolver;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.processor.DeadLetterChannel;
 import org.apache.camel.impl.DefaultCamelContext;
 
 import java.util.ArrayList;
@@ -79,6 +80,17 @@
      */
     public RouteBuilder<E> errorHandler(ErrorHandlerBuilder errorHandlerBuilder) {
         setErrorHandlerBuilder(errorHandlerBuilder);
+        return this;
+    }
+
+    /**
+     * Configures whether or not the error handler is inherited by every processing node
(or just the top most one)
+     *
+     * @param value the falg as to whether error handlers should be inherited or not
+     * @return the current builder
+     */
+    public RouteBuilder<E> inheritErrorHandler(boolean value) {
+        setInheritErrorHandler(value);
         return this;
     }
 

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java?view=diff&rev=520962&r1=520961&r2=520962
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java
Wed Mar 21 10:45:38 2007
@@ -17,15 +17,15 @@
  */
 package org.apache.camel.builder;
 
-import junit.framework.TestCase;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.TestSupport;
-import org.apache.camel.processor.LoggingErrorHandler;
-import org.apache.camel.processor.SendProcessor;
 import org.apache.camel.processor.DeadLetterChannel;
+import org.apache.camel.processor.FilterProcessor;
+import org.apache.camel.processor.LoggingErrorHandler;
 import org.apache.camel.processor.RedeliveryPolicy;
+import org.apache.camel.processor.SendProcessor;
 
 import java.util.Map;
 import java.util.Set;
@@ -34,10 +34,11 @@
  * @version $Revision$
  */
 public class ErrorHandlerTest extends TestSupport {
+    /*
     public void testOverloadingTheDefaultErrorHandler() throws Exception {
 
         // START SNIPPET: e1
-        RouteBuilder<Exchange> builder1 = new RouteBuilder<Exchange>() {
+        RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() {
             public void configure() {
                 errorHandler(loggingErrorHandler("FOO.BAR"));
 
@@ -45,7 +46,6 @@
             }
         };
         // END SNIPPET: e1
-        RouteBuilder<Exchange> builder = builder1;
 
         Map<Endpoint<Exchange>, Processor<Exchange>> routeMap = builder.getRouteMap();
         Set<Map.Entry<Endpoint<Exchange>, Processor<Exchange>>> routes
= routeMap.entrySet();
@@ -62,7 +62,7 @@
     public void testOverloadingTheHandlerOnASingleRoute() throws Exception {
 
         // START SNIPPET: e2
-        RouteBuilder<Exchange> builder1 = new RouteBuilder<Exchange>() {
+        RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() {
             public void configure() {
                 from("queue:a").errorHandler(loggingErrorHandler("FOO.BAR")).to("queue:b");
 
@@ -71,7 +71,6 @@
             }
         };
         // END SNIPPET: e2
-        RouteBuilder<Exchange> builder = builder1;
 
         Map<Endpoint<Exchange>, Processor<Exchange>> routeMap = builder.getRouteMap();
         log.info(routeMap);
@@ -102,7 +101,7 @@
     public void testConfigureDeadLetterChannel() throws Exception {
 
         // START SNIPPET: e3
-        RouteBuilder<Exchange> builder1 = new RouteBuilder<Exchange>() {
+        RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() {
             public void configure() {
                 errorHandler(deadLetterChannel("queue:errors"));
 
@@ -110,7 +109,6 @@
             }
         };
         // END SNIPPET: e3
-        RouteBuilder<Exchange> builder = builder1;
 
         Map<Endpoint<Exchange>, Processor<Exchange>> routeMap = builder.getRouteMap();
         Set<Map.Entry<Endpoint<Exchange>, Processor<Exchange>>> routes
= routeMap.entrySet();
@@ -129,7 +127,7 @@
     public void testConfigureDeadLetterChannelWithCustomRedeliveryPolicy() throws Exception
{
 
         // START SNIPPET: e4
-        RouteBuilder<Exchange> builder1 = new RouteBuilder<Exchange>() {
+        RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() {
             public void configure() {
                 errorHandler(deadLetterChannel("queue:errors").maximumRedeliveries(2).useExponentialBackOff());
 
@@ -137,7 +135,6 @@
             }
         };
         // END SNIPPET: e4
-        RouteBuilder<Exchange> builder = builder1;
 
         Map<Endpoint<Exchange>, Processor<Exchange>> routeMap = builder.getRouteMap();
         Set<Map.Entry<Endpoint<Exchange>, Processor<Exchange>>> routes
= routeMap.entrySet();
@@ -154,6 +151,31 @@
             assertEquals("getMaximumRedeliveries()", 2, redeliveryPolicy.getMaximumRedeliveries());
             assertEquals("isUseExponentialBackOff()", true, redeliveryPolicy.isUseExponentialBackOff());
         }
-    }
+    }         */
+
+    public void testDisablingInheritenceOfErrorHandlers() throws Exception {
+
+        // START SNIPPET: e5
+        RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() {
+            public void configure() {
+                inheritErrorHandler(false);
+
+                from("queue:a").errorHandler(loggingErrorHandler("FOO.BAR")).filter(body().isInstanceOf(String.class)).to("queue:b");
+            }
+        };
+        // END SNIPPET: e5
 
+        Map<Endpoint<Exchange>, Processor<Exchange>> routeMap = builder.getRouteMap();
+        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", "queue:a", key.getEndpointUri());
+            Processor processor = route.getValue();
+
+            LoggingErrorHandler loggingProcessor = assertIsInstanceOf(LoggingErrorHandler.class,
processor);
+            FilterProcessor filterProcessor = assertIsInstanceOf(FilterProcessor.class, loggingProcessor.getOutput());
+            SendProcessor sendProcessor = assertIsInstanceOf(SendProcessor.class, filterProcessor.getProcessor());
+        }
+    }
 }



Mime
View raw message