camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [11/24] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is using hystrix
Date Tue, 19 Apr 2016 16:19:30 GMT
CAMEL-9879: Circuit Breaker EIP - That is using hystrix


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

Branch: refs/heads/master
Commit: f180fbeb8e1344c7b7cd069fc97dff5fef3b73b7
Parents: 6f75174
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Apr 19 08:49:34 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Apr 19 18:16:45 2016 +0200

----------------------------------------------------------------------
 .../component/hystrix/HystrixProcessor.java     | 29 +-------------------
 .../hystrix/HystrixProcessorCommand.java        | 13 +++++----
 2 files changed, 9 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f180fbeb/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
index 495706f..22d48af 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessor.java
@@ -85,20 +85,13 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
 
     @Override
     public boolean process(Exchange exchange, AsyncCallback callback) {
-        // run this as if we run inside try .. catch so there is no regular Camel error handler
-        exchange.setProperty(Exchange.TRY_ROUTE_BLOCK, true);
-
-        // use our callback that does some cleanup when done
-        AsyncCallback hystrixCallback = new HystrixAsyncCallback(exchange, callback);
-
         HystrixCommandGroupKey key = HystrixCommandGroupKey.Factory.asKey(id);
-        HystrixProcessorCommand command = new HystrixProcessorCommand(key, exchange, hystrixCallback,
processor, fallback);
+        HystrixProcessorCommand command = new HystrixProcessorCommand(key, exchange, callback,
processor, fallback);
         try {
             command.queue();
         } catch (Throwable e) {
             // error adding to queue, so set as error and we are done
             exchange.setException(e);
-            exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
             callback.done(true);
             return true;
         }
@@ -116,24 +109,4 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
         // noop
     }
 
-    private static final class HystrixAsyncCallback implements AsyncCallback {
-
-        private final Exchange exchange;
-        private final AsyncCallback delegate;
-
-        public HystrixAsyncCallback(Exchange exchange, AsyncCallback delegate) {
-            this.exchange = exchange;
-            this.delegate = delegate;
-        }
-
-        @Override
-        public void done(boolean doneSync) {
-            if (doneSync) {
-                return;
-            }
-            // we are only done when called with false
-            exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
-            delegate.done(doneSync);
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/f180fbeb/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
index 299819e..1eec854 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixProcessorCommand.java
@@ -54,6 +54,7 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange>
{
 
         try {
             if (fallback != null) {
+                LOG.debug("Error occurred processing. Will now run fallback. Exception class:
{} message: {}.", exception.getClass().getName(), exception.getMessage());
                 // store the last to endpoint as the failure endpoint
                 if (exchange.getProperty(Exchange.FAILURE_ENDPOINT) == null) {
                     exchange.setProperty(Exchange.FAILURE_ENDPOINT, exchange.getProperty(Exchange.TO_ENDPOINT));
@@ -66,14 +67,15 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange>
{
                 exchange.removeProperty(Exchange.REDELIVERY_EXHAUSTED);
                 // run the fallback processor
                 try {
-                    LOG.debug("Running fallback: {}", exchange);
+                    LOG.debug("Running fallback: {} with exchange: {}", fallback, exchange);
                     fallback.process(exchange, callback);
                 } catch (Exception e) {
                     exchange.setException(e);
                 }
             }
         } finally {
-            LOG.debug("Running fallback: {} success", exchange);
+            LOG.debug("Running fallback: {} with exchange: {} done", fallback, exchange);
+            exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
             callback.done(false);
         }
 
@@ -82,9 +84,9 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange>
{
 
     @Override
     protected Exchange run() throws Exception {
-        LOG.debug("Running processor: {}", exchange);
+        LOG.debug("Running processor: {} with exchange: {}", processor, exchange);
 
-        exchange.setProperty(Exchange.EXCEPTION_HANDLED, null);
+        // run this as if we run inside try .. catch so there is no regular Camel error handler
         exchange.setProperty(Exchange.TRY_ROUTE_BLOCK, true);
         try {
             processor.process(exchange, callback);
@@ -98,7 +100,8 @@ public class HystrixProcessorCommand extends HystrixCommand<Exchange>
{
         }
         // no errors we are done
         try {
-            LOG.debug("Running processor: {} success", exchange);
+            LOG.debug("Running processor: {} with exchange: {} done", processor, exchange);
+            exchange.removeProperty(Exchange.TRY_ROUTE_BLOCK);
             callback.done(false);
         } catch (Throwable e) {
             exchange.setException(e);


Mime
View raw message