camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-7974: Circuit break store state on exchange
Date Fri, 07 Aug 2015 15:12:59 GMT
Repository: camel
Updated Branches:
  refs/heads/master 805db35b4 -> 98e8657e2


CAMEL-7974: Circuit break store state on exchange


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/68c6c1ad
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/68c6c1ad
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/68c6c1ad

Branch: refs/heads/master
Commit: 68c6c1ad9606c5dd911b3e6978c9bb84d6505c6e
Parents: 805db35
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Aug 7 17:15:19 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Aug 7 17:15:32 2015 +0200

----------------------------------------------------------------------
 .../src/main/java/org/apache/camel/Exchange.java   | 17 +++++++++--------
 .../loadbalancer/CircuitBreakerLoadBalancer.java   | 14 ++++++++++++++
 2 files changed, 23 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/68c6c1ad/camel-core/src/main/java/org/apache/camel/Exchange.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/Exchange.java b/camel-core/src/main/java/org/apache/camel/Exchange.java
index 8e7cc84..1780b65 100644
--- a/camel-core/src/main/java/org/apache/camel/Exchange.java
+++ b/camel-core/src/main/java/org/apache/camel/Exchange.java
@@ -94,12 +94,13 @@ public interface Exchange {
     // used across other Apache products such as AMQ, SMX etc.
     String BREADCRUMB_ID              = "breadcrumbId";
 
-    String CHARSET_NAME      = "CamelCharsetName";
-    String CREATED_TIMESTAMP = "CamelCreatedTimestamp";
-    String CONTENT_ENCODING  = "Content-Encoding";
-    String CONTENT_LENGTH    = "Content-Length";
-    String CONTENT_TYPE      = "Content-Type";
-    String CORRELATION_ID    = "CamelCorrelationId";
+    String CHARSET_NAME          = "CamelCharsetName";
+    String CIRCUIT_BREAKER_STATE = "CamelCircuitBreakerState";
+    String CREATED_TIMESTAMP     = "CamelCreatedTimestamp";
+    String CONTENT_ENCODING      = "Content-Encoding";
+    String CONTENT_LENGTH        = "Content-Length";
+    String CONTENT_TYPE          = "Content-Type";
+    String CORRELATION_ID        = "CamelCorrelationId";
 
     String DATASET_INDEX             = "CamelDataSetIndex";
     String DEFAULT_CHARSET_PROPERTY  = "org.apache.camel.default.charset";
@@ -118,7 +119,6 @@ public interface Exchange {
     String FAILURE_HANDLED      = "CamelFailureHandled";
     String FAILURE_ENDPOINT     = "CamelFailureEndpoint";
     String FAILURE_ROUTE_ID     = "CamelFailureRouteId";
-    String FILTER_NON_XML_CHARS = "CamelFilterNonXmlChars";
     String FILE_CONTENT_TYPE    = "CamelFileContentType";
     String FILE_LOCAL_WORK_PATH = "CamelFileLocalWorkPath";
     String FILE_NAME            = "CamelFileName";
@@ -129,11 +129,12 @@ public interface Exchange {
     String FILE_PARENT          = "CamelFileParent";
     String FILE_LAST_MODIFIED   = "CamelFileLastModified";
     String FILE_LENGTH          = "CamelFileLength";
-    String FILTER_MATCHED       = "CamelFilterMatched";
     String FILE_LOCK_FILE_ACQUIRED = "CamelFileLockFileAcquired";
     String FILE_LOCK_FILE_NAME  = "CamelFileLockFileName";
     String FILE_LOCK_EXCLUSIVE_LOCK = "CamelFileLockExclusiveLock";
     String FILE_LOCK_RANDOM_ACCESS_FILE = "CamelFileLockRandomAccessFile";
+    String FILTER_MATCHED       = "CamelFilterMatched";
+    String FILTER_NON_XML_CHARS = "CamelFilterNonXmlChars";
 
     String GROUPED_EXCHANGE = "CamelGroupedExchange";
     

http://git-wip-us.apache.org/repos/asf/camel/blob/68c6c1ad/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/CircuitBreakerLoadBalancer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/CircuitBreakerLoadBalancer.java
b/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/CircuitBreakerLoadBalancer.java
index abb2758..3f3c484 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/CircuitBreakerLoadBalancer.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/CircuitBreakerLoadBalancer.java
@@ -225,6 +225,9 @@ public class CircuitBreakerLoadBalancer extends LoadBalancerSupport implements
T
             throw new IllegalStateException("No processors could be chosen to process CircuitBreaker");
         }
 
+        // store state as exchange property
+        exchange.setProperty(Exchange.CIRCUIT_BREAKER_STATE, stateAsString());
+
         AsyncProcessor albp = AsyncProcessorConverterHelper.convert(processor);
         // Added a callback for processing the exchange in the callback
         boolean sync = albp.process(exchange, new CircuitBreakerCallback(exchange, callback));
@@ -256,6 +259,17 @@ public class CircuitBreakerLoadBalancer extends LoadBalancerSupport implements
T
         return true;
     }
 
+    private String stateAsString() {
+        int num = state.get();
+        if (num == STATE_CLOSED) {
+            return "closed";
+        } else if (num == STATE_HALF_OPEN) {
+            return "halfOpen";
+        } else {
+            return "open";
+        }
+    }
+
     public String toString() {
         return "CircuitBreakerLoadBalancer[" + getProcessors() + "]";
     }


Mime
View raw message