camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r812426 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/management/ main/java/org/apache/camel/management/mbean/ test/java/org/apache/camel/management/
Date Tue, 08 Sep 2009 10:09:15 GMT
Author: davsclaus
Date: Tue Sep  8 10:09:15 2009
New Revision: 812426

URL: http://svn.apache.org/viewvc?rev=812426&view=rev
Log:
CAMEL-1996: Added more managed attributes for managing error handlers.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedErrorHandlerRedeliveryTest.java
      - copied, changed from r812410, camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedErrorHandlerTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedErrorHandler.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java?rev=812426&r1=812425&r2=812426&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
Tue Sep  8 10:09:15 2009
@@ -132,7 +132,7 @@
 
             // it has not then its an indirection and we should do some work to lookup the
real builder
             ref = builderRef.getRef();
-            builder = builderRef.lookupErrorHandlerBuilder(routeContext, builderRef.getRef());
+            builder = ErrorHandlerBuilderRef.lookupErrorHandlerBuilder(routeContext, builderRef.getRef());
 
             // must do a 2nd lookup in case this is also a reference
             // (this happens with spring DSL using errorHandlerRef on <route> as it
gets a bit
@@ -141,7 +141,7 @@
                 builderRef = (ErrorHandlerBuilderRef) builder;
                 // does it refer to a non default error handler then do a 2nd lookup
                 if (!builderRef.getRef().equals(ErrorHandlerBuilderRef.DEFAULT_ERROR_HANDLER_BUILDER))
{
-                    builder = builderRef.lookupErrorHandlerBuilder(routeContext, builderRef.getRef());
+                    builder = ErrorHandlerBuilderRef.lookupErrorHandlerBuilder(routeContext,
builderRef.getRef());
                     ref = builderRef.getRef();
                 }
             }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedErrorHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedErrorHandler.java?rev=812426&r1=812425&r2=812426&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedErrorHandler.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedErrorHandler.java
Tue Sep  8 10:09:15 2009
@@ -16,9 +16,9 @@
  */
 package org.apache.camel.management.mbean;
 
+import org.apache.camel.LoggingLevel;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.ErrorHandlerBuilder;
-import org.apache.camel.builder.ErrorHandlerBuilderRef;
 import org.apache.camel.processor.RedeliveryErrorHandler;
 import org.apache.camel.spi.RouteContext;
 import org.springframework.jmx.export.annotation.ManagedAttribute;
@@ -64,14 +64,242 @@
 
     @ManagedAttribute(description = "RedeliveryPolicy for maximum redeliveries")
     public Integer getMaximumRedeliveries() {
-        if (errorHandler instanceof RedeliveryErrorHandler) {
-            RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
-            return redelivery.getRedeliveryPolicy().getMaximumRedeliveries();
+        if (!isSupportRedelivery()) {
+            return null;
         }
-        // not supported
-        return null;
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        return redelivery.getRedeliveryPolicy().getMaximumRedeliveries();
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for maximum redeliveries")
+    public void setMaximumRedeliveries(Integer maximum) {
+        if (!isSupportRedelivery()) {
+            throw new IllegalArgumentException("This error handler does not support redelivery");
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        redelivery.getRedeliveryPolicy().setMaximumRedeliveries(maximum);
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for maximum redelivery delay")
+    public Long getMaximumRedeliveryDelay() {
+        if (!isSupportRedelivery()) {
+            return null;
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        return redelivery.getRedeliveryPolicy().getMaximumRedeliveryDelay();
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for maximum redelivery delay")
+    public void setMaximumRedeliveryDelay(Long delay) {
+        if (!isSupportRedelivery()) {
+            throw new IllegalArgumentException("This error handler does not support redelivery");
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        redelivery.getRedeliveryPolicy().setMaximumRedeliveryDelay(delay);
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for redelivery delay")
+    public Long getRedeliveryDelay() {
+        if (!isSupportRedelivery()) {
+            return null;
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        return redelivery.getRedeliveryPolicy().getRedeliverDelay();
     }
 
-    // TODO: work in progress
+    @ManagedAttribute(description = "RedeliveryPolicy for redelivery delay")
+    public void setRedeliveryDelay(Long delay) {
+        if (!isSupportRedelivery()) {
+            throw new IllegalArgumentException("This error handler does not support redelivery");
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        redelivery.getRedeliveryPolicy().setRedeliverDelay(delay);
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for backoff multipler")
+    public Double getBackOffMultiplier() {
+        if (!isSupportRedelivery()) {
+            return null;
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        return redelivery.getRedeliveryPolicy().getBackOffMultiplier();
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for backoff multipler")
+    public void setBackOffMultiplier(Double multiplier) {
+        if (!isSupportRedelivery()) {
+            throw new IllegalArgumentException("This error handler does not support redelivery");
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        redelivery.getRedeliveryPolicy().setBackOffMultiplier(multiplier);
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for collision avoidance factor")
+    public Double getCollisionAvoidanceFactor() {
+        if (!isSupportRedelivery()) {
+            return null;
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        return redelivery.getRedeliveryPolicy().getCollisionAvoidanceFactor();
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for collision avoidance factor")
+    public void setCollisionAvoidanceFactor(Double factor) {
+        if (!isSupportRedelivery()) {
+            throw new IllegalArgumentException("This error handler does not support redelivery");
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        redelivery.getRedeliveryPolicy().setCollisionAvoidanceFactor(factor);
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for collision avoidance percent")
+    public Double getCollisionAvoidancePercent() {
+        if (!isSupportRedelivery()) {
+            return null;
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        return (double) redelivery.getRedeliveryPolicy().getCollisionAvoidancePercent();
 
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for collision avoidance percent")
+    public void setCollisionAvoidancePercent(Double percent) {
+        if (!isSupportRedelivery()) {
+            throw new IllegalArgumentException("This error handler does not support redelivery");
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        redelivery.getRedeliveryPolicy().setCollisionAvoidancePercent(percent);
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for delay pattern")
+    public String getDelayPattern() {
+        if (!isSupportRedelivery()) {
+            return null;
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        return redelivery.getRedeliveryPolicy().getDelayPattern();
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for delay pattern")
+    public void setDelayPattern(String pattern) {
+        if (!isSupportRedelivery()) {
+            throw new IllegalArgumentException("This error handler does not support redelivery");
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        redelivery.getRedeliveryPolicy().setDelayPattern(pattern);
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for logging level when retries exhausted")
+    public String getRetriesExhaustedLogLevel() {
+        if (!isSupportRedelivery()) {
+            return null;
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        return redelivery.getRedeliveryPolicy().getRetriesExhaustedLogLevel().name();
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for logging level when retries exhausted")
+    public void setRetriesExhaustedLogLevel(String level) {
+        if (!isSupportRedelivery()) {
+            throw new IllegalArgumentException("This error handler does not support redelivery");
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        redelivery.getRedeliveryPolicy().setRetriesExhaustedLogLevel(LoggingLevel.valueOf(level));
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for logging level when attempting retry")
+    public String getRetryAttemptedLogLevel() {
+        if (!isSupportRedelivery()) {
+            return null;
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        return redelivery.getRedeliveryPolicy().getRetryAttemptedLogLevel().name();
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for logging level when attempting retry")
+    public void setRetryAttemptedLogLevel(String level) {
+        if (!isSupportRedelivery()) {
+            throw new IllegalArgumentException("This error handler does not support redelivery");
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        redelivery.getRedeliveryPolicy().setRetryAttemptedLogLevel(LoggingLevel.valueOf(level));
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for logging stack traces")
+    public Boolean getLogStackTrace() {
+        if (!isSupportRedelivery()) {
+            return null;
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        return redelivery.getRedeliveryPolicy().isLogStackTrace();
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for logging stack traces")
+    public void setLogStackTrace(Boolean log) {
+        if (!isSupportRedelivery()) {
+            throw new IllegalArgumentException("This error handler does not support redelivery");
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        redelivery.getRedeliveryPolicy().setLogStackTrace(log);
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for using collision avoidance")
+    public Boolean getUseCollisionAvoidance() {
+        if (!isSupportRedelivery()) {
+            return null;
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        return redelivery.getRedeliveryPolicy().isUseCollisionAvoidance();
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for using collision avoidance")
+    public void setUseCollisionAvoidance(Boolean avoidance) {
+        if (!isSupportRedelivery()) {
+            throw new IllegalArgumentException("This error handler does not support redelivery");
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        redelivery.getRedeliveryPolicy().setUseCollisionAvoidance(avoidance);
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for using exponential backoff")
+    public Boolean getUseExponentialBackOff() {
+        if (!isSupportRedelivery()) {
+            return null;
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        return redelivery.getRedeliveryPolicy().isUseExponentialBackOff();
+    }
+
+    @ManagedAttribute(description = "RedeliveryPolicy for using exponential backoff")
+    public void setUseExponentialBackOff(Boolean backoff) {
+        if (!isSupportRedelivery()) {
+            throw new IllegalArgumentException("This error handler does not support redelivery");
+        }
+
+        RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+        redelivery.getRedeliveryPolicy().setUseExponentialBackOff(backoff);
+    }
 
 }

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedErrorHandlerRedeliveryTest.java
(from r812410, camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedErrorHandlerTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedErrorHandlerRedeliveryTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedErrorHandlerRedeliveryTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedErrorHandlerTest.java&r1=812410&r2=812426&rev=812426&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedErrorHandlerTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedErrorHandlerRedeliveryTest.java
Tue Sep  8 10:09:15 2009
@@ -16,19 +16,25 @@
  */
 package org.apache.camel.management;
 
-import java.util.Iterator;
 import java.util.Set;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
+import javax.management.Attribute;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.CamelExecutionException;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  * @version $Revision$
  */
-public class ManagedErrorHandlerTest extends ContextTestSupport {
+public class ManagedErrorHandlerRedeliveryTest extends ContextTestSupport {
+
+    private static int counter;
 
     @Override
     protected CamelContext createCamelContext() throws Exception {
@@ -39,22 +45,47 @@
         return context;
     }
 
-    public void testManagedErrorHandler() throws Exception {
+    public void testManagedErrorHandlerRedelivery() throws Exception {
+        counter = 0;
+
         MBeanServer mbeanServer = context.getManagementStrategy().getManagementAgent().getMBeanServer();
 
         Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=errorhandlers,*"),
null);
-        // there should only be 2 error handler types as route 1 and route 3 uses the same
default error handler
-        assertEquals(2, set.size());
+        assertEquals(1, set.size());
+        ObjectName on = set.iterator().next();
+
+        Integer max = (Integer) mbeanServer.getAttribute(on, "MaximumRedeliveries");
+        assertEquals(5, max.intValue());
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
 
-        Iterator<ObjectName> it = set.iterator();
-        ObjectName on1 = it.next();
-        ObjectName on2 = it.next();
+        assertEquals(3, counter);
 
-        String name1 = on1.getCanonicalName();
-        String name2 = on2.getCanonicalName();
+        assertMockEndpointsSatisfied();
 
-        assertTrue("Should be a default error handler", name1.contains("CamelDefaultErrorHandlerBuilder")
|| name2.contains("CamelDefaultErrorHandlerBuilder"));
-        assertTrue("Should be a dead letter error handler", name1.contains("DeadLetterChannelBuilder")
|| name2.contains("DeadLetterChannelBuilder"));
+        // now change to 0 attempts and try again
+        counter = 0;
+        mock.reset();
+        mock.expectedMessageCount(0);
+        mbeanServer.setAttribute(on, new Attribute("MaximumRedeliveries", 0));
+
+        try {
+            template.sendBody("direct:start", "Bye World");
+            fail("Should have thrown exception");
+        } catch (CamelExecutionException e) {
+            IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class,
e.getCause());
+            assertEquals("Forced", cause.getMessage());
+
+        }
+
+        assertEquals(1, counter);
+
+        // and should now be 0
+        max = (Integer) mbeanServer.getAttribute(on, "MaximumRedeliveries");
+        assertEquals(0, max.intValue());
     }
 
     @Override
@@ -62,12 +93,17 @@
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:foo").to("mock:foo");
-
-                from("direct:bar").errorHandler(deadLetterChannel("mock:dead")).to("mock:bar");
+                errorHandler(defaultErrorHandler().maximumRedeliveries(5));
 
-                from("direct:baz").to("mock:baz");
+                from("direct:start").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        counter++;
+                        if (counter < 3) {
+                            throw new  IllegalArgumentException("Forced");
+                        }
+                    }
+                }).to("mock:result");
             }
         };
     }
-}
+}
\ No newline at end of file



Mime
View raw message