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/4b67c6c4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4b67c6c4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4b67c6c4

Branch: refs/heads/master
Commit: 4b67c6c4bb753a95ae081d64b9bfb922c919a332
Parents: 2e3745f
Author: Claus Ibsen <[email protected]>
Authored: Tue Apr 19 14:59:14 2016 +0200
Committer: Claus Ibsen <[email protected]>
Committed: Tue Apr 19 18:16:45 2016 +0200

----------------------------------------------------------------------
 .../processor/HystrixProcessorFactory.java      | 189 ++++++++++---------
 1 file changed, 97 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4b67c6c4/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorFactory.java
----------------------------------------------------------------------
diff --git 
a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorFactory.java
 
b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorFactory.java
index bc1cca8..276275d 100644
--- 
a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorFactory.java
+++ 
b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorFactory.java
@@ -59,99 +59,15 @@ public class HystrixProcessorFactory implements 
ProcessorFactory {
             HystrixThreadPoolProperties.Setter threadPool = 
HystrixThreadPoolProperties.Setter();
             setter.andThreadPoolPropertiesDefaults(threadPool);
 
-            // any custom configuration then override the setter
-            if (cb.getHystrixConfiguration() != null || 
cb.getHystrixConfigurationRef() != null) {
+            // at first configure any shared options
+            if (cb.getHystrixConfigurationRef() != null) {
+                HystrixConfigurationDefinition config = 
CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), 
cb.getHystrixConfigurationRef(), HystrixConfigurationDefinition.class);
+                configureHystrix(command, threadPool, config);
+            }
+            // then any local configured can override
+            if (cb.getHystrixConfiguration() != null) {
                 HystrixConfigurationDefinition config = 
cb.getHystrixConfiguration();
-                if (config == null && cb.getHystrixConfigurationRef() != null) 
{
-                    config = 
CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), 
cb.getHystrixConfigurationRef(), HystrixConfigurationDefinition.class);
-                }
-
-                // command
-                if (config.getCircuitBreakerEnabled() != null) {
-                    
command.withCircuitBreakerEnabled(config.getCircuitBreakerEnabled());
-                }
-                if (config.getCircuitBreakerErrorThresholdPercentage() != 
null) {
-                    
command.withCircuitBreakerErrorThresholdPercentage(config.getCircuitBreakerErrorThresholdPercentage());
-                }
-                if (config.getCircuitBreakerForceClosed() != null) {
-                    
command.withCircuitBreakerForceClosed(config.getCircuitBreakerForceClosed());
-                }
-                if (config.getCircuitBreakerForceOpen() != null) {
-                    
command.withCircuitBreakerForceOpen(config.getCircuitBreakerForceOpen());
-                }
-                if (config.getCircuitBreakerRequestVolumeThreshold() != null) {
-                    
command.withCircuitBreakerRequestVolumeThreshold(config.getCircuitBreakerRequestVolumeThreshold());
-                }
-                if (config.getCircuitBreakerSleepWindowInMilliseconds() != 
null) {
-                    
command.withCircuitBreakerSleepWindowInMilliseconds(config.getCircuitBreakerSleepWindowInMilliseconds());
-                }
-                if 
(config.getExecutionIsolationSemaphoreMaxConcurrentRequests() != null) {
-                    
command.withExecutionIsolationSemaphoreMaxConcurrentRequests(config.getExecutionIsolationSemaphoreMaxConcurrentRequests());
-                }
-                if (config.getExecutionIsolationStrategy() != null) {
-                    
command.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.valueOf(config.getExecutionIsolationStrategy()));
-                }
-                if (config.getExecutionIsolationThreadInterruptOnTimeout() != 
null) {
-                    
command.withExecutionIsolationThreadInterruptOnTimeout(config.getExecutionIsolationThreadInterruptOnTimeout());
-                }
-                if (config.getExecutionTimeoutInMilliseconds() != null) {
-                    
command.withExecutionTimeoutInMilliseconds(config.getExecutionTimeoutInMilliseconds());
-                }
-                if (config.getExecutionTimeoutEnabled() != null) {
-                    
command.withExecutionTimeoutEnabled(config.getExecutionTimeoutEnabled());
-                }
-                if 
(config.getFallbackIsolationSemaphoreMaxConcurrentRequests() != null) {
-                    
command.withFallbackIsolationSemaphoreMaxConcurrentRequests(config.getFallbackIsolationSemaphoreMaxConcurrentRequests());
-                }
-                if (config.getFallbackEnabled() != null) {
-                    command.withFallbackEnabled(config.getFallbackEnabled());
-                }
-                if (config.getMetricsHealthSnapshotIntervalInMilliseconds() != 
null) {
-                    
command.withMetricsHealthSnapshotIntervalInMilliseconds(config.getMetricsHealthSnapshotIntervalInMilliseconds());
-                }
-                if (config.getMetricsRollingPercentileBucketSize() != null) {
-                    
command.withMetricsRollingPercentileBucketSize(config.getMetricsRollingPercentileBucketSize());
-                }
-                if (config.getMetricsRollingPercentileEnabled() != null) {
-                    
command.withMetricsRollingPercentileEnabled(config.getMetricsRollingPercentileEnabled());
-                }
-                if (config.getMetricsRollingPercentileWindowInMilliseconds() 
!= null) {
-                    
command.withMetricsRollingPercentileWindowInMilliseconds(config.getMetricsRollingPercentileWindowInMilliseconds());
-                }
-                if (config.getMetricsRollingPercentileWindowBuckets() != null) 
{
-                    
command.withMetricsRollingPercentileWindowBuckets(config.getMetricsRollingPercentileWindowBuckets());
-                }
-                if (config.getMetricsRollingStatisticalWindowInMilliseconds() 
!= null) {
-                    
command.withMetricsRollingStatisticalWindowInMilliseconds(config.getMetricsRollingStatisticalWindowInMilliseconds());
-                }
-                if (config.getMetricsRollingStatisticalWindowBuckets() != 
null) {
-                    
command.withMetricsRollingStatisticalWindowBuckets(config.getMetricsRollingStatisticalWindowBuckets());
-                }
-                if (config.getRequestCacheEnabled() != null) {
-                    
command.withRequestCacheEnabled(config.getRequestCacheEnabled());
-                }
-                if (config.getRequestLogEnabled() != null) {
-                    
command.withRequestLogEnabled(config.getRequestLogEnabled());
-                }
-                // thread pool
-                if (config.getCorePoolSize() != null) {
-                    threadPool.withCoreSize(config.getCorePoolSize());
-                }
-                if (config.getKeepAliveTime() != null) {
-                    
threadPool.withKeepAliveTimeMinutes(config.getKeepAliveTime());
-                }
-                if (config.getMaxQueueSize() != null) {
-                    threadPool.withMaxQueueSize(config.getMaxQueueSize());
-                }
-                if (config.getQueueSizeRejectionThreshold() != null) {
-                    
threadPool.withQueueSizeRejectionThreshold(config.getQueueSizeRejectionThreshold());
-                }
-                if 
(config.getThreadPoolRollingNumberStatisticalWindowInMilliseconds() != null) {
-                    
threadPool.withMetricsRollingStatisticalWindowInMilliseconds(config.getThreadPoolRollingNumberStatisticalWindowInMilliseconds());
-                }
-                if 
(config.getThreadPoolRollingNumberStatisticalWindowBuckets() != null) {
-                    
threadPool.withMetricsRollingStatisticalWindowBuckets(config.getThreadPoolRollingNumberStatisticalWindowBuckets());
-                }
+                configureHystrix(command, threadPool, config);
             }
 
             return new HystrixProcessor(id, setter, processor, fallback);
@@ -159,4 +75,93 @@ public class HystrixProcessorFactory implements 
ProcessorFactory {
             return null;
         }
     }
+
+    private void configureHystrix(HystrixCommandProperties.Setter command, 
HystrixThreadPoolProperties.Setter threadPool, HystrixConfigurationDefinition 
config) {
+        // command
+        if (config.getCircuitBreakerEnabled() != null) {
+            
command.withCircuitBreakerEnabled(config.getCircuitBreakerEnabled());
+        }
+        if (config.getCircuitBreakerErrorThresholdPercentage() != null) {
+            
command.withCircuitBreakerErrorThresholdPercentage(config.getCircuitBreakerErrorThresholdPercentage());
+        }
+        if (config.getCircuitBreakerForceClosed() != null) {
+            
command.withCircuitBreakerForceClosed(config.getCircuitBreakerForceClosed());
+        }
+        if (config.getCircuitBreakerForceOpen() != null) {
+            
command.withCircuitBreakerForceOpen(config.getCircuitBreakerForceOpen());
+        }
+        if (config.getCircuitBreakerRequestVolumeThreshold() != null) {
+            
command.withCircuitBreakerRequestVolumeThreshold(config.getCircuitBreakerRequestVolumeThreshold());
+        }
+        if (config.getCircuitBreakerSleepWindowInMilliseconds() != null) {
+            
command.withCircuitBreakerSleepWindowInMilliseconds(config.getCircuitBreakerSleepWindowInMilliseconds());
+        }
+        if (config.getExecutionIsolationSemaphoreMaxConcurrentRequests() != 
null) {
+            
command.withExecutionIsolationSemaphoreMaxConcurrentRequests(config.getExecutionIsolationSemaphoreMaxConcurrentRequests());
+        }
+        if (config.getExecutionIsolationStrategy() != null) {
+            
command.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.valueOf(config.getExecutionIsolationStrategy()));
+        }
+        if (config.getExecutionIsolationThreadInterruptOnTimeout() != null) {
+            
command.withExecutionIsolationThreadInterruptOnTimeout(config.getExecutionIsolationThreadInterruptOnTimeout());
+        }
+        if (config.getExecutionTimeoutInMilliseconds() != null) {
+            
command.withExecutionTimeoutInMilliseconds(config.getExecutionTimeoutInMilliseconds());
+        }
+        if (config.getExecutionTimeoutEnabled() != null) {
+            
command.withExecutionTimeoutEnabled(config.getExecutionTimeoutEnabled());
+        }
+        if (config.getFallbackIsolationSemaphoreMaxConcurrentRequests() != 
null) {
+            
command.withFallbackIsolationSemaphoreMaxConcurrentRequests(config.getFallbackIsolationSemaphoreMaxConcurrentRequests());
+        }
+        if (config.getFallbackEnabled() != null) {
+            command.withFallbackEnabled(config.getFallbackEnabled());
+        }
+        if (config.getMetricsHealthSnapshotIntervalInMilliseconds() != null) {
+            
command.withMetricsHealthSnapshotIntervalInMilliseconds(config.getMetricsHealthSnapshotIntervalInMilliseconds());
+        }
+        if (config.getMetricsRollingPercentileBucketSize() != null) {
+            
command.withMetricsRollingPercentileBucketSize(config.getMetricsRollingPercentileBucketSize());
+        }
+        if (config.getMetricsRollingPercentileEnabled() != null) {
+            
command.withMetricsRollingPercentileEnabled(config.getMetricsRollingPercentileEnabled());
+        }
+        if (config.getMetricsRollingPercentileWindowInMilliseconds() != null) {
+            
command.withMetricsRollingPercentileWindowInMilliseconds(config.getMetricsRollingPercentileWindowInMilliseconds());
+        }
+        if (config.getMetricsRollingPercentileWindowBuckets() != null) {
+            
command.withMetricsRollingPercentileWindowBuckets(config.getMetricsRollingPercentileWindowBuckets());
+        }
+        if (config.getMetricsRollingStatisticalWindowInMilliseconds() != null) 
{
+            
command.withMetricsRollingStatisticalWindowInMilliseconds(config.getMetricsRollingStatisticalWindowInMilliseconds());
+        }
+        if (config.getMetricsRollingStatisticalWindowBuckets() != null) {
+            
command.withMetricsRollingStatisticalWindowBuckets(config.getMetricsRollingStatisticalWindowBuckets());
+        }
+        if (config.getRequestCacheEnabled() != null) {
+            command.withRequestCacheEnabled(config.getRequestCacheEnabled());
+        }
+        if (config.getRequestLogEnabled() != null) {
+            command.withRequestLogEnabled(config.getRequestLogEnabled());
+        }
+        // thread pool
+        if (config.getCorePoolSize() != null) {
+            threadPool.withCoreSize(config.getCorePoolSize());
+        }
+        if (config.getKeepAliveTime() != null) {
+            threadPool.withKeepAliveTimeMinutes(config.getKeepAliveTime());
+        }
+        if (config.getMaxQueueSize() != null) {
+            threadPool.withMaxQueueSize(config.getMaxQueueSize());
+        }
+        if (config.getQueueSizeRejectionThreshold() != null) {
+            
threadPool.withQueueSizeRejectionThreshold(config.getQueueSizeRejectionThreshold());
+        }
+        if (config.getThreadPoolRollingNumberStatisticalWindowInMilliseconds() 
!= null) {
+            
threadPool.withMetricsRollingStatisticalWindowInMilliseconds(config.getThreadPoolRollingNumberStatisticalWindowInMilliseconds());
+        }
+        if (config.getThreadPoolRollingNumberStatisticalWindowBuckets() != 
null) {
+            
threadPool.withMetricsRollingStatisticalWindowBuckets(config.getThreadPoolRollingNumberStatisticalWindowBuckets());
+        }
+    }
 }

Reply via email to