You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/11/29 09:52:39 UTC
svn commit: r1040038 -
/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java
Author: davsclaus
Date: Mon Nov 29 08:52:38 2010
New Revision: 1040038
URL: http://svn.apache.org/viewvc?rev=1040038&view=rev
Log:
Improved logging
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java?rev=1040038&r1=1040037&r2=1040038&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java Mon Nov 29 08:52:38 2010
@@ -86,22 +86,28 @@ public class FailOverLoadBalancer extend
* @return <tt>true</tt> to failover
*/
protected boolean shouldFailOver(Exchange exchange) {
- if (exchange.getException() != null) {
+ boolean answer = false;
+ if (exchange.getException() != null) {
if (exceptions == null || exceptions.isEmpty()) {
// always failover if no exceptions defined
- return true;
- }
-
- for (Class<?> exception : exceptions) {
- // will look in exception hierarchy
- if (exchange.getException(exception) != null) {
- return true;
+ answer = true;
+ } else {
+ for (Class<?> exception : exceptions) {
+ // will look in exception hierarchy
+ if (exchange.getException(exception) != null) {
+ answer = true;
+ break;
+ }
}
}
}
- return false;
+ if (log.isTraceEnabled()) {
+ log.trace("Should failover: " + answer + " for exchangeId: " + exchange.getExchangeId());
+ }
+
+ return answer;
}
public boolean process(Exchange exchange, AsyncCallback callback) {
@@ -118,8 +124,8 @@ public class FailOverLoadBalancer extend
}
index.set(counter.get());
}
- if (log.isDebugEnabled()) {
- log.debug("Failover starting with endpoint index " + index);
+ if (log.isTraceEnabled()) {
+ log.trace("Failover starting with endpoint index " + index);
}
while (first || shouldFailOver(exchange)) {
@@ -143,12 +149,12 @@ public class FailOverLoadBalancer extend
if (index.get() >= processors.size()) {
// out of bounds
if (isRoundRobin()) {
- log.debug("Failover is round robin enabled and therefore starting from the first endpoint");
+ log.trace("Failover is round robin enabled and therefore starting from the first endpoint");
index.set(0);
counter.set(0);
} else {
// no more processors to try
- log.debug("Braking out of failover as we reach the end of endpoints to use for failover");
+ log.trace("Braking out of failover as we reach the end of endpoints to use for failover");
break;
}
}
@@ -175,8 +181,8 @@ public class FailOverLoadBalancer extend
}
}
- if (log.isTraceEnabled()) {
- log.trace("Failover complete for exchangeId: " + exchange.getExchangeId() + " >>> " + exchange);
+ if (log.isDebugEnabled()) {
+ log.debug("Failover complete for exchangeId: " + exchange.getExchangeId() + " >>> " + exchange);
}
callback.done(true);
@@ -189,7 +195,14 @@ public class FailOverLoadBalancer extend
* @param exchange the exchange
*/
protected void prepareExchangeForFailover(Exchange exchange) {
- exchange.setException(null);
+ if (exchange.getException() != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Failover due " + exchange.getException().getMessage() + " for exchangeId: " + exchange.getExchangeId());
+ }
+
+ // clear exception so we can try failover
+ exchange.setException(null);
+ }
exchange.setProperty(Exchange.ERRORHANDLER_HANDLED, null);
exchange.setProperty(Exchange.FAILURE_HANDLED, null);
@@ -242,8 +255,8 @@ public class FailOverLoadBalancer extend
attempts.incrementAndGet();
// are we exhausted by attempts?
if (maximumFailoverAttempts > -1 && attempts.get() > maximumFailoverAttempts) {
- if (log.isDebugEnabled()) {
- log.debug("Braking out of failover after " + attempts + " failover attempts");
+ if (log.isTraceEnabled()) {
+ log.trace("Braking out of failover after " + attempts + " failover attempts");
}
break;
}
@@ -254,12 +267,12 @@ public class FailOverLoadBalancer extend
if (index.get() >= processors.size()) {
// out of bounds
if (isRoundRobin()) {
- log.debug("Failover is round robin enabled and therefore starting from the first endpoint");
+ log.trace("Failover is round robin enabled and therefore starting from the first endpoint");
index.set(0);
counter.set(0);
} else {
// no more processors to try
- log.debug("Braking out of failover as we reach the end of endpoints to use for failover");
+ log.trace("Braking out of failover as we reach the end of endpoints to use for failover");
break;
}
}
@@ -280,6 +293,10 @@ public class FailOverLoadBalancer extend
}
}
+ if (log.isDebugEnabled()) {
+ log.debug("Failover complete for exchangeId: " + exchange.getExchangeId() + " >>> " + exchange);
+ }
+
// signal callback we are done
callback.done(false);
};