camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1389943 - in /camel/branches/camel-2.10.x: ./ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/test/java/org/apache/camel/processor/
Date Tue, 25 Sep 2012 15:49:06 GMT
Author: davsclaus
Date: Tue Sep 25 15:49:05 2012
New Revision: 1389943

URL: http://svn.apache.org/viewvc?rev=1389943&view=rev
Log:
CAMEL-5638: Scheduled poll consumer should invoke exception handler on rollback strategy.
This allows people to bridge error handler and deal with the caused exception in Camel routes.
For example a ftp login error or the likes.

Added:
    camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/processor/DefaultScheduledPollConsumerBridgeErrorHandlerTest.java
      - copied unchanged from r1389941, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultScheduledPollConsumerBridgeErrorHandlerTest.java
Modified:
    camel/branches/camel-2.10.x/   (props changed)
    camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumerPollStrategy.java
    camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1389941

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumerPollStrategy.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumerPollStrategy.java?rev=1389943&r1=1389942&r2=1389943&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumerPollStrategy.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumerPollStrategy.java
Tue Sep 25 15:49:05 2012
@@ -18,15 +18,12 @@ package org.apache.camel.impl;
 
 import org.apache.camel.Consumer;
 import org.apache.camel.Endpoint;
-import org.apache.camel.StatefulService;
 import org.apache.camel.spi.PollingConsumerPollStrategy;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * A default implementation that just logs a <tt>WARN</tt> level log in case
of rollback.
- * <p/>
- * The implement will <b>not</b> log if the rollback occurred during shutdown.
+ * A default implementation that will not retry on rollback.
  *
  * @version 
  */
@@ -43,16 +40,6 @@ public class DefaultPollingConsumerPollS
     }
 
     public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception
e) throws Exception {
-        boolean runAllowed = true;
-        if (consumer instanceof StatefulService) {
-            runAllowed = ((StatefulService) consumer).isRunAllowed();
-        }
-
-        // only log warn if we are running, otherwise we are just stopping which we should
not log the issue in the logs
-        if (runAllowed) {
-            log.warn("Consumer " + consumer +  " could not poll endpoint: " + endpoint +
" caused by: " + e.getMessage(), e);
-        }
-
         // we do not want to retry
         return false;
     }

Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java?rev=1389943&r1=1389942&r2=1389943&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
Tue Sep 25 15:49:05 2012
@@ -26,6 +26,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.LoggingLevel;
 import org.apache.camel.PollingConsumerPollingStrategy;
 import org.apache.camel.Processor;
+import org.apache.camel.StatefulService;
 import org.apache.camel.SuspendableService;
 import org.apache.camel.spi.PollingConsumerPollStrategy;
 import org.apache.camel.util.ObjectHelper;
@@ -117,9 +118,11 @@ public abstract class ScheduledPollConsu
 
         int retryCounter = -1;
         boolean done = false;
+        Throwable cause = null;
 
         while (!done) {
             try {
+                cause = null;
                 // eager assume we are done
                 done = true;
                 if (isPollAllowed()) {
@@ -157,22 +160,32 @@ public abstract class ScheduledPollConsu
                 try {
                     boolean retry = pollStrategy.rollback(this, getEndpoint(), retryCounter,
e);
                     if (retry) {
+                        // do not set cause as we retry
                         done = false;
+                    } else {
+                        cause = e;
+                        done = true;
                     }
                 } catch (Throwable t) {
-                    // catch throwable to not let the thread die
-                    getExceptionHandler().handleException("Consumer " + this +  " failed
polling endpoint: " + getEndpoint()
-                            + ". Will try again at next poll", t);
-                    // we are done due this fatal error
+                    cause = t;
                     done = true;
                 }
             } catch (Throwable t) {
-                // catch throwable to not let the thread die
-                getExceptionHandler().handleException("Consumer " + this +  " failed polling
endpoint: " + getEndpoint()
-                        + ". Will try again at next poll", t);
-                // we are done due this fatal error
+                cause = t;
                 done = true;
             }
+
+            if (cause != null && isRunAllowed()) {
+                // let exception handler deal with the caused exception
+                // but suppress this during shutdown as the logs may get flooded with exceptions
during shutdown/forced shutdown
+                try {
+                    getExceptionHandler().handleException("Consumer " + this +  " failed
polling endpoint: " + getEndpoint()
+                            + ". Will try again at next poll", cause);
+                } catch (Throwable e) {
+                    LOG.warn("Error handling exception. This exception will be ignored.",
e);
+                }
+                cause = null;
+            }
         }
 
         // avoid this thread to throw exceptions because the thread pool wont re-schedule
a new thread



Mime
View raw message