camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1382489 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/model/ camel-core/src/main/java/org/apache/camel/processor/ camel-core/...
Date Sun, 09 Sep 2012 13:06:59 GMT
Author: davsclaus
Date: Sun Sep  9 13:06:58 2012
New Revision: 1382489

URL: http://svn.apache.org/viewvc?rev=1382489&view=rev
Log:
CAMEL-3364: Added option redeliverWhileStopping to control if redelivery is allowed during
stopping a route. Turn this off to stop quicker by not allowing redeliveriers.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliveryErrorHandlerNoRedeliveryOnShutdownTest.java
  (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRedeliveryErrorHandlerNoRedeliveryOnShutdownTest.java
      - copied, changed from r1382483, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAOPBeforeTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringRedeliveryErrorHandlerNoRedeliveryOnShutdownTest.xml
      - copied, changed from r1382483, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopbefore.xml
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DefaultErrorHandlerBuilder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/RedeliveryPolicyDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java
    camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelRedeliveryPolicyFactoryBean.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DefaultErrorHandlerBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DefaultErrorHandlerBuilder.java?rev=1382489&r1=1382488&r2=1382489&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DefaultErrorHandlerBuilder.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DefaultErrorHandlerBuilder.java
Sun Sep  9 13:06:58 2012
@@ -167,6 +167,17 @@ public class DefaultErrorHandlerBuilder 
     }
 
     /**
+     * Controls whether to allow redelivery while stopping/shutting down a route that uses
error handling.
+     *
+     * @param redeliverWhileStopping <tt>true</tt> to allow redelivery, <tt>false</tt>
to reject redeliveries
+     * @return the builder
+     */
+    public DefaultErrorHandlerBuilder redeliverWhileStopping(boolean redeliverWhileStopping)
{
+        getRedeliveryPolicy().setRedeliverWhileStopping(redeliverWhileStopping);
+        return this;
+    }
+
+    /**
      * Sets a reference to a thread pool to be used for redelivery.
      *
      * @param ref reference to a scheduled thread pool

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java?rev=1382489&r1=1382488&r2=1382489&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java
Sun Sep  9 13:06:58 2012
@@ -189,6 +189,7 @@ public class DefaultShutdownStrategy ext
             } else {
                 if (forceShutdown || shutdownNowOnTimeout) {
                     LOG.warn("Timeout occurred. Now forcing the routes to be shutdown now.");
+                    forceShutdown = true;
                     // force the routes to shutdown now
                     shutdownRoutesNow(routesOrdered);
 
@@ -373,7 +374,8 @@ public class DefaultShutdownStrategy ext
     private static void prepareShutdown(Service service, boolean forced, boolean includeChildren)
{
         Set<Service> list;
         if (includeChildren) {
-            list = ServiceHelper.getChildServices(service);
+            // include error handlers as we want to prepare them for shutdown as well
+            list = ServiceHelper.getChildServices(service, true);
         } else {
             list = new LinkedHashSet<Service>(1);
             list.add(service);
@@ -499,6 +501,17 @@ public class DefaultShutdownStrategy ext
                 }
             }
 
+            // notify the services we intend to shutdown
+            for (RouteStartupOrder order : routes) {
+                for (Service service : order.getServices()) {
+                    // skip the consumer as we handle that specially
+                    if (service instanceof Consumer) {
+                        continue;
+                    }
+                    prepareShutdown(service, false, true);
+                }
+            }
+
             // wait till there are no more pending and inflight messages
             boolean done = false;
             long loopDelaySeconds = 1;

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RedeliveryPolicyDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RedeliveryPolicyDefinition.java?rev=1382489&r1=1382488&r2=1382489&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/RedeliveryPolicyDefinition.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/RedeliveryPolicyDefinition.java
Sun Sep  9 13:06:58 2012
@@ -71,6 +71,8 @@ public class RedeliveryPolicyDefinition 
     private String disableRedelivery;
     @XmlAttribute
     private String delayPattern;
+    @XmlAttribute
+    private String redeliverWhileStopping;
 
     public RedeliveryPolicy createRedeliveryPolicy(CamelContext context, RedeliveryPolicy
parentPolicy) {
 
@@ -142,6 +144,9 @@ public class RedeliveryPolicyDefinition 
             if (delayPattern != null) {
                 answer.setDelayPattern(delayPattern);
             }
+            if (redeliverWhileStopping != null) {
+                answer.setLogExhausted(CamelContextHelper.parseBoolean(context, redeliverWhileStopping));
+            }
         } catch (Exception e) {
             throw ObjectHelper.wrapRuntimeCamelException(e);
         }
@@ -166,6 +171,21 @@ public class RedeliveryPolicyDefinition 
     }
 
     /**
+     * Allow synchronous delayed redelivery.
+     */
+    public RedeliveryPolicyDefinition redeliverWhileStopping(boolean redeliverWhileStopping)
{
+        return redeliverWhileStopping(Boolean.toString(redeliverWhileStopping));
+    }
+
+    /**
+     * Allow synchronous delayed redelivery.
+     */
+    public RedeliveryPolicyDefinition redeliverWhileStopping(String redeliverWhileStopping)
{
+        setRedeliverWhileStopping(redeliverWhileStopping);
+        return this;
+    }
+
+    /**
      * Sets the back off multiplier
      *
      * @param backOffMultiplier  the back off multiplier
@@ -640,4 +660,12 @@ public class RedeliveryPolicyDefinition 
     public void setDelayPattern(String delayPattern) {
         this.delayPattern = delayPattern;
     }
+
+    public String getRedeliverWhileStopping() {
+        return redeliverWhileStopping;
+    }
+
+    public void setRedeliverWhileStopping(String redeliverWhileStopping) {
+        this.redeliverWhileStopping = redeliverWhileStopping;
+    }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java?rev=1382489&r1=1382488&r2=1382489&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
Sun Sep  9 13:06:58 2012
@@ -30,6 +30,7 @@ import org.apache.camel.Message;
 import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
 import org.apache.camel.model.OnExceptionDefinition;
+import org.apache.camel.spi.ShutdownPrepared;
 import org.apache.camel.spi.SubUnitOfWorkCallback;
 import org.apache.camel.spi.UnitOfWork;
 import org.apache.camel.util.AsyncProcessorConverterHelper;
@@ -51,7 +52,7 @@ import org.apache.camel.util.ServiceHelp
  *
  * @version
  */
-public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport implements AsyncProcessor
{
+public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport implements AsyncProcessor,
ShutdownPrepared {
 
     protected ScheduledExecutorService executorService;
     protected final CamelContext camelContext;
@@ -65,6 +66,7 @@ public abstract class RedeliveryErrorHan
     protected final CamelLogger logger;
     protected final boolean useOriginalMessagePolicy;
     protected boolean redeliveryEnabled;
+    protected volatile boolean preparingShutdown;
 
     /**
      * Contains the current redelivery data
@@ -86,6 +88,7 @@ public abstract class RedeliveryErrorHan
         Predicate continuedPredicate;
         boolean useOriginalInMessage = useOriginalMessagePolicy;
         boolean asyncDelayedRedelivery = redeliveryPolicy.isAsyncDelayedRedelivery();
+        boolean redeliverWhileStopping = redeliveryPolicy.isRedeliverWhileStopping();
     }
 
     /**
@@ -198,14 +201,38 @@ public abstract class RedeliveryErrorHan
         return false;
     }
 
-    @Override
-    public boolean isRunAllowed() {
-        // determine if we can still run, or the camel context is forcing a shutdown
+    protected boolean isRunAllowed(RedeliveryData data) {
+        // if camel context is forcing a shutdown then do not allow running
         boolean forceShutdown = camelContext.getShutdownStrategy().forceShutdown(this);
         if (forceShutdown) {
-            log.trace("Run not allowed as ShutdownStrategy is forcing shutting down");
+            log.trace("isRunAllowed() -> false (Run not allowed as ShutdownStrategy is
forcing shutting down)");
+            return false;
+        }
+
+        // redelivery policy can control if redelivery is allowed during stopping/shutdown
+        // but this only applies during a redelivery (counter must > 0)
+        if (data.redeliveryCounter > 0) {
+            if (data.redeliverWhileStopping) {
+                log.trace("isRunAllowed() -> true (Run allowed as RedeliverWhileStopping
is enabled)");
+                return true;
+            } else if (preparingShutdown) {
+                // do not allow redelivery as we are preparing for shutdown
+                log.trace("isRunAllowed() -> false (Run not allowed as we are preparing
for shutdown)");
+                return false;
+            }
         }
-        return !forceShutdown && super.isRunAllowed();
+
+        // fallback and use code from super
+        boolean answer = super.isRunAllowed();
+        log.trace("isRunAllowed() -> {} (Run allowed if we are not stopped/stopping)",
answer);
+        return answer;
+    }
+
+    @Override
+    public void prepareShutdown(boolean forced) {
+        // prepare for shutdown, eg do not allow redelivery if configured
+        log.trace("Prepare shutdown on error handler {}", this);
+        preparingShutdown = true;
     }
 
     public void process(Exchange exchange) throws Exception {
@@ -233,7 +260,7 @@ public abstract class RedeliveryErrorHan
         while (true) {
 
             // can we still run
-            if (!isRunAllowed()) {
+            if (!isRunAllowed(data)) {
                 log.trace("Run not allowed, will reject executing exchange: {}", exchange);
                 if (exchange.getException() == null) {
                     exchange.setException(new RejectedExecutionException());
@@ -404,7 +431,7 @@ public abstract class RedeliveryErrorHan
      */
     protected void processAsyncErrorHandler(final Exchange exchange, final AsyncCallback
callback, final RedeliveryData data) {
         // can we still run
-        if (!isRunAllowed()) {
+        if (!isRunAllowed(data)) {
             log.trace("Run not allowed, will reject executing exchange: {}", exchange);
             if (exchange.getException() == null) {
                 exchange.setException(new RejectedExecutionException());
@@ -1071,6 +1098,9 @@ public abstract class RedeliveryErrorHan
                 log.trace("Using ExecutorService: {} for redeliveries on error handler: {}",
executorService, this);
             }
         }
+
+        // reset flag when starting
+        preparingShutdown = false;
     }
 
     @Override

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java?rev=1382489&r1=1382488&r2=1382489&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
Sun Sep  9 13:06:58 2012
@@ -96,6 +96,7 @@ public class RedeliveryPolicy implements
     protected boolean logRetryAttempted = true;
     protected String delayPattern;
     protected boolean asyncDelayedRedelivery;
+    protected boolean redeliverWhileStopping = true;
 
     public RedeliveryPolicy() {
     }
@@ -106,6 +107,7 @@ public class RedeliveryPolicy implements
             + ", redeliveryDelay=" + redeliveryDelay
             + ", maximumRedeliveryDelay=" + maximumRedeliveryDelay
             + ", asyncDelayedRedelivery=" + asyncDelayedRedelivery
+            + ", redeliverWhileStopping=" + redeliverWhileStopping
             + ", retriesExhaustedLogLevel=" + retriesExhaustedLogLevel
             + ", retryAttemptedLogLevel=" + retryAttemptedLogLevel
             + ", logRetryAttempted=" + logRetryAttempted
@@ -403,6 +405,16 @@ public class RedeliveryPolicy implements
         return this;
     }
 
+    /**
+     * Controls whether to allow redelivery while stopping/shutting down a route that uses
error handling.
+     *
+     * @param redeliverWhileStopping <tt>true</tt> to allow redelivery, <tt>false</tt>
to reject redeliveries
+     */
+    public RedeliveryPolicy redeliverWhileStopping(boolean redeliverWhileStopping) {
+        setRedeliverWhileStopping(redeliverWhileStopping);
+        return this;
+    }
+
     // Properties
     // -------------------------------------------------------------------------
 
@@ -647,4 +659,18 @@ public class RedeliveryPolicy implements
     public void setAsyncDelayedRedelivery(boolean asyncDelayedRedelivery) {
         this.asyncDelayedRedelivery = asyncDelayedRedelivery;
     }
+
+    public boolean isRedeliverWhileStopping() {
+        return redeliverWhileStopping;
+    }
+
+    /**
+     * Controls whether to allow redelivery while stopping/shutting down a route that uses
error handling.
+     *
+     * @param redeliverWhileStopping <tt>true</tt> to allow redelivery, <tt>false</tt>
to reject redeliveries
+     */
+    public void setRedeliverWhileStopping(boolean redeliverWhileStopping) {
+        this.redeliverWhileStopping = redeliverWhileStopping;
+    }
+
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java?rev=1382489&r1=1382488&r2=1382489&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java Sun Sep
 9 13:06:58 2012
@@ -22,11 +22,14 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.camel.Channel;
 import org.apache.camel.Navigate;
+import org.apache.camel.Processor;
 import org.apache.camel.Service;
 import org.apache.camel.ShutdownableService;
 import org.apache.camel.StatefulService;
 import org.apache.camel.SuspendableService;
+import org.apache.camel.processor.ErrorHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -366,20 +369,38 @@ public final class ServiceHelper {
      * @return the services, including the parent service, and all its children
      */
     public static Set<Service> getChildServices(Service service) {
+        return getChildServices(service, false);
+    }
+
+    /**
+     * Gather all child services by navigating the service to recursively gather all child
services.
+     *
+     * @param service the service
+     * @param includeErrorHandler whether to include error handlers
+     * @return the services, including the parent service, and all its children
+     */
+    public static Set<Service> getChildServices(Service service, boolean includeErrorHandler)
{
         Set<Service> answer = new LinkedHashSet<Service>();
-        doGetChildServices(answer, service);
+        doGetChildServices(answer, service, includeErrorHandler);
         return answer;
     }
 
-    private static void doGetChildServices(Set<Service> services, Service service)
{
+    private static void doGetChildServices(Set<Service> services, Service service,
boolean includeErrorHandler) {
         services.add(service);
         if (service instanceof Navigate) {
             Navigate<?> nav = (Navigate<?>) service;
             if (nav.hasNext()) {
                 List<?> children = nav.next();
                 for (Object child : children) {
+                    // special for error handler as they are tied to the Channel
+                    if (child instanceof Channel && includeErrorHandler) {
+                        Processor errorHandler = ((Channel) child).getErrorHandler();
+                        if (errorHandler != null && errorHandler instanceof Service)
{
+                            services.add((Service) errorHandler);
+                        }
+                    }
                     if (child instanceof Service) {
-                        doGetChildServices(services, (Service) child);
+                        doGetChildServices(services, (Service) child, includeErrorHandler);
                     }
                 }
             }

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliveryErrorHandlerNoRedeliveryOnShutdownTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliveryErrorHandlerNoRedeliveryOnShutdownTest.java?rev=1382489&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliveryErrorHandlerNoRedeliveryOnShutdownTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliveryErrorHandlerNoRedeliveryOnShutdownTest.java
Sun Sep  9 13:06:58 2012
@@ -0,0 +1,64 @@
+/**
+ * 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;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.LoggingLevel;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.util.StopWatch;
+
+/**
+ *
+ */
+public class RedeliveryErrorHandlerNoRedeliveryOnShutdownTest extends ContextTestSupport
{
+
+    public void testRedeliveryErrorHandlerNoRedeliveryOnShutdown() throws Exception {
+        getMockEndpoint("mock:foo").expectedMessageCount(1);
+
+        template.sendBody("seda:foo", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        // should not take long to stop the route
+        StopWatch watch = new StopWatch();
+        context.stopRoute("foo");
+        watch.stop();
+
+        assertTrue("Should stop route faster, was " + watch.taken(), watch.taken() < 4000);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // START SNIPPET: e1
+
+                // this error handler will try up till 20 redelivery attempts with 1 second
between.
+                // however if we are stopping then do not allow any redeliver attempts.
+                errorHandler(defaultErrorHandler()
+                        .redeliverWhileStopping(false)
+                        .maximumRedeliveries(20).redeliveryDelay(1000).retryAttemptedLogLevel(LoggingLevel.INFO));
+
+                from("seda:foo").routeId("foo")
+                    .to("mock:foo")
+                    .throwException(new IllegalArgumentException("Forced"));
+                // END SNIPPET: e1
+            }
+        };
+    }
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliveryErrorHandlerNoRedeliveryOnShutdownTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliveryErrorHandlerNoRedeliveryOnShutdownTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelRedeliveryPolicyFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelRedeliveryPolicyFactoryBean.java?rev=1382489&r1=1382488&r2=1382489&view=diff
==============================================================================
--- camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelRedeliveryPolicyFactoryBean.java
(original)
+++ camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelRedeliveryPolicyFactoryBean.java
Sun Sep  9 13:06:58 2012
@@ -69,6 +69,8 @@ public abstract class AbstractCamelRedel
     private String disableRedelivery;
     @XmlAttribute
     private String delayPattern;
+    @XmlAttribute
+    private String redeliverWhileStopping;
 
     public RedeliveryPolicy getObject() throws Exception {
         RedeliveryPolicy answer = new RedeliveryPolicy();
@@ -133,6 +135,9 @@ public abstract class AbstractCamelRedel
         if (delayPattern != null) {
             answer.setDelayPattern(CamelContextHelper.parseText(context, delayPattern));
         }
+        if (redeliverWhileStopping != null) {
+            answer.setRedeliverWhileStopping(CamelContextHelper.parseBoolean(context, redeliverWhileStopping));
+        }
 
         return answer;
     }
@@ -284,4 +289,12 @@ public abstract class AbstractCamelRedel
     public void setDelayPattern(String delayPattern) {
         this.delayPattern = delayPattern;
     }
+
+    public String getRedeliverWhileStopping() {
+        return redeliverWhileStopping;
+    }
+
+    public void setRedeliverWhileStopping(String redeliverWhileStopping) {
+        this.redeliverWhileStopping = redeliverWhileStopping;
+    }
 }
\ No newline at end of file

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRedeliveryErrorHandlerNoRedeliveryOnShutdownTest.java
(from r1382483, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAOPBeforeTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRedeliveryErrorHandlerNoRedeliveryOnShutdownTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRedeliveryErrorHandlerNoRedeliveryOnShutdownTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAOPBeforeTest.java&r1=1382483&r2=1382489&rev=1382489&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAOPBeforeTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRedeliveryErrorHandlerNoRedeliveryOnShutdownTest.java
Sun Sep  9 13:06:58 2012
@@ -17,15 +17,16 @@
 package org.apache.camel.spring.processor;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.processor.AOPBeforeTest;
+import org.apache.camel.processor.RedeliveryErrorHandlerNoRedeliveryOnShutdownTest;
+
 import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
 
 /**
  * @version 
  */
-public class SpringAOPBeforeTest extends AOPBeforeTest {
+public class SpringRedeliveryErrorHandlerNoRedeliveryOnShutdownTest extends RedeliveryErrorHandlerNoRedeliveryOnShutdownTest
{
 
     protected CamelContext createCamelContext() throws Exception {
-        return createSpringCamelContext(this, "org/apache/camel/spring/processor/aopbefore.xml");
+        return createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringRedeliveryErrorHandlerNoRedeliveryOnShutdownTest.xml");
     }
 }
\ No newline at end of file

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringRedeliveryErrorHandlerNoRedeliveryOnShutdownTest.xml
(from r1382483, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopbefore.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringRedeliveryErrorHandlerNoRedeliveryOnShutdownTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringRedeliveryErrorHandlerNoRedeliveryOnShutdownTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopbefore.xml&r1=1382483&r2=1382489&rev=1382489&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopbefore.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringRedeliveryErrorHandlerNoRedeliveryOnShutdownTest.xml
Sun Sep  9 13:06:58 2012
@@ -22,15 +22,27 @@
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
+	<!-- exception to be thrown to force redelivery -->
+	<bean id="forced" class="java.lang.IllegalArgumentException">
+		<constructor-arg index="0" value="Forced"/>
+	</bean>
+
     <!-- START SNIPPET: e1 -->
-    <camelContext xmlns="http://camel.apache.org/schema/spring">
-        <route>
-            <from uri="direct:start"/>
-            <aop beforeUri="mock:before">
-                <transform><constant>Bye World</constant></transform>
-                <to uri="mock:result"/>
-            </aop>
+	<!-- notice we use the errorHandlerRef attribute to refer to the error handler to use
as default -->
+    <camelContext errorHandlerRef="myErrorHandler" xmlns="http://camel.apache.org/schema/spring">
+
+		<!-- configure error handler, to redeliver up till 10 times, with 1 sec delay
+		     and if we are stopping then do not allow redeliveries, to stop faster -->
+		<errorHandler id="myErrorHandler" type="DefaultErrorHandler">
+			<redeliveryPolicy maximumRedeliveries="20" redeliveryDelay="1000" redeliverWhileStopping="false"
retryAttemptedLogLevel="INFO"/>
+		</errorHandler>
+
+        <route id="foo">
+            <from uri="seda:foo"/>
+			<to uri="mock:foo"/>
+			<throwException ref="forced"/>
         </route>
+
     </camelContext>
     <!-- END SNIPPET: e1 -->
 



Mime
View raw message