001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.model;
018
019import java.util.concurrent.BlockingQueue;
020import java.util.concurrent.Future;
021import java.util.concurrent.ThreadPoolExecutor;
022import java.util.concurrent.TimeUnit;
023
024import javax.xml.bind.annotation.XmlAccessType;
025import javax.xml.bind.annotation.XmlAccessorType;
026import javax.xml.bind.annotation.XmlAttribute;
027
028import org.apache.camel.spi.Metadata;
029
030@XmlAccessorType(XmlAccessType.FIELD)
031@Deprecated
032public class HystrixConfigurationCommon extends IdentifiedType {
033
034    @XmlAttribute
035    @Metadata(defaultValue = "CamelHystrix")
036    private String groupKey;
037    @XmlAttribute
038    @Metadata(defaultValue = "CamelHystrix")
039    private String threadPoolKey;
040    @XmlAttribute
041    @Metadata(javaType = "java.lang.Boolean", label = "command", defaultValue = "true")
042    private String circuitBreakerEnabled;
043    @XmlAttribute
044    @Metadata(javaType = "java.lang.Integer", label = "command", defaultValue = "50")
045    private String circuitBreakerErrorThresholdPercentage;
046    @XmlAttribute
047    @Metadata(javaType = "java.lang.Boolean", label = "command", defaultValue = "false")
048    private String circuitBreakerForceClosed;
049    @XmlAttribute
050    @Metadata(javaType = "java.lang.Boolean", label = "command", defaultValue = "false")
051    private String circuitBreakerForceOpen;
052    @XmlAttribute
053    @Metadata(javaType = "java.lang.Integer", label = "command", defaultValue = "20")
054    private String circuitBreakerRequestVolumeThreshold;
055    @XmlAttribute
056    @Metadata(javaType = "java.lang.Integer", label = "command", defaultValue = "5000")
057    private String circuitBreakerSleepWindowInMilliseconds;
058    @XmlAttribute
059    @Metadata(javaType = "java.lang.Integer", label = "command", defaultValue = "20")
060    private String executionIsolationSemaphoreMaxConcurrentRequests;
061    @XmlAttribute
062    @Metadata(label = "command", defaultValue = "THREAD", enums = "THREAD,SEMAPHORE")
063    private String executionIsolationStrategy;
064    @XmlAttribute
065    @Metadata(javaType = "java.lang.Boolean", label = "command", defaultValue = "true")
066    private String executionIsolationThreadInterruptOnTimeout;
067    @XmlAttribute
068    @Metadata(javaType = "java.lang.Integer", label = "command", defaultValue = "1000")
069    private String executionTimeoutInMilliseconds;
070    @XmlAttribute
071    @Metadata(javaType = "java.lang.Boolean", label = "command", defaultValue = "true")
072    private String executionTimeoutEnabled;
073    @XmlAttribute
074    @Metadata(javaType = "java.lang.Integer", label = "command", defaultValue = "10")
075    private String fallbackIsolationSemaphoreMaxConcurrentRequests;
076    @XmlAttribute
077    @Metadata(javaType = "java.lang.Boolean", label = "command", defaultValue = "true")
078    private String fallbackEnabled;
079    @XmlAttribute
080    @Metadata(javaType = "java.lang.Integer", label = "command", defaultValue = "500")
081    private String metricsHealthSnapshotIntervalInMilliseconds;
082    @XmlAttribute
083    @Metadata(javaType = "java.lang.Integer", label = "command", defaultValue = "10")
084    private String metricsRollingPercentileBucketSize;
085    @XmlAttribute
086    @Metadata(javaType = "java.lang.Boolean", label = "command", defaultValue = "true")
087    private String metricsRollingPercentileEnabled;
088    @XmlAttribute
089    @Metadata(javaType = "java.lang.Integer", label = "command", defaultValue = "10000")
090    private String metricsRollingPercentileWindowInMilliseconds;
091    @XmlAttribute
092    @Metadata(javaType = "java.lang.Integer", label = "command", defaultValue = "6")
093    private String metricsRollingPercentileWindowBuckets;
094    @XmlAttribute
095    @Metadata(javaType = "java.lang.Integer", label = "command", defaultValue = "10000")
096    private String metricsRollingStatisticalWindowInMilliseconds;
097    @XmlAttribute
098    @Metadata(javaType = "java.lang.Integer", label = "command", defaultValue = "10")
099    private String metricsRollingStatisticalWindowBuckets;
100    @XmlAttribute
101    @Metadata(javaType = "java.lang.Boolean", label = "command", defaultValue = "true")
102    private String requestLogEnabled;
103
104    // thread-pool
105
106    @XmlAttribute
107    @Metadata(javaType = "java.lang.Integer", label = "threadpool", defaultValue = "10")
108    private String corePoolSize;
109    @XmlAttribute
110    @Metadata(javaType = "java.lang.Integer", label = "threadpool", defaultValue = "10")
111    private String maximumSize;
112    @XmlAttribute
113    @Metadata(javaType = "java.lang.Integer", label = "threadpool", defaultValue = "1")
114    private String keepAliveTime;
115    @XmlAttribute
116    @Metadata(javaType = "java.lang.Integer", label = "threadpool", defaultValue = "-1")
117    private String maxQueueSize;
118    @XmlAttribute
119    @Metadata(javaType = "java.lang.Integer", label = "threadpool", defaultValue = "5")
120    private String queueSizeRejectionThreshold;
121    @XmlAttribute
122    @Metadata(javaType = "java.lang.Integer", label = "threadpool", defaultValue = "10000")
123    private String threadPoolRollingNumberStatisticalWindowInMilliseconds;
124    @XmlAttribute
125    @Metadata(javaType = "java.lang.Integer", label = "threadpool", defaultValue = "10")
126    private String threadPoolRollingNumberStatisticalWindowBuckets;
127    @XmlAttribute
128    @Metadata(javaType = "java.lang.Boolean", label = "threadpool", defaultValue = "false")
129    private String allowMaximumSizeToDivergeFromCoreSize;
130
131    // Getter/Setter
132    // -------------------------------------------------------------------------
133
134    public String getGroupKey() {
135        return groupKey;
136    }
137
138    /**
139     * Sets the group key to use. The default value is CamelHystrix.
140     */
141    public void setGroupKey(String groupKey) {
142        this.groupKey = groupKey;
143    }
144
145    public String getThreadPoolKey() {
146        return threadPoolKey;
147    }
148
149    /**
150     * Sets the thread pool key to use. Will by default use the same value as
151     * groupKey has been configured to use.
152     */
153    public void setThreadPoolKey(String threadPoolKey) {
154        this.threadPoolKey = threadPoolKey;
155    }
156
157    public String getCircuitBreakerEnabled() {
158        return circuitBreakerEnabled;
159    }
160
161    /**
162     * Whether to use a HystrixCircuitBreaker or not. If false no
163     * circuit-breaker logic will be used and all requests permitted.
164     * <p>
165     * This is similar in effect to circuitBreakerForceClosed() except that
166     * continues tracking metrics and knowing whether it should be open/closed,
167     * this property results in not even instantiating a circuit-breaker.
168     */
169    public void setCircuitBreakerEnabled(String circuitBreakerEnabled) {
170        this.circuitBreakerEnabled = circuitBreakerEnabled;
171    }
172
173    public String getCircuitBreakerErrorThresholdPercentage() {
174        return circuitBreakerErrorThresholdPercentage;
175    }
176
177    /**
178     * Error percentage threshold (as whole number such as 50) at which point
179     * the circuit breaker will trip open and reject requests.
180     * <p>
181     * It will stay tripped for the duration defined in
182     * circuitBreakerSleepWindowInMilliseconds;
183     * <p>
184     * The error percentage this is compared against comes from
185     * HystrixCommandMetrics.getHealthCounts().
186     */
187    public void setCircuitBreakerErrorThresholdPercentage(String circuitBreakerErrorThresholdPercentage) {
188        this.circuitBreakerErrorThresholdPercentage = circuitBreakerErrorThresholdPercentage;
189    }
190
191    public String getCircuitBreakerForceClosed() {
192        return circuitBreakerForceClosed;
193    }
194
195    /**
196     * If true the HystrixCircuitBreaker#allowRequest() will always return true
197     * to allow requests regardless of the error percentage from
198     * HystrixCommandMetrics.getHealthCounts().
199     * <p>
200     * The circuitBreakerForceOpen() property takes precedence so if it set to
201     * true this property does nothing.
202     */
203    public void setCircuitBreakerForceClosed(String circuitBreakerForceClosed) {
204        this.circuitBreakerForceClosed = circuitBreakerForceClosed;
205    }
206
207    public String getCircuitBreakerForceOpen() {
208        return circuitBreakerForceOpen;
209    }
210
211    /**
212     * If true the HystrixCircuitBreaker.allowRequest() will always return
213     * false, causing the circuit to be open (tripped) and reject all requests.
214     * <p>
215     * This property takes precedence over circuitBreakerForceClosed();
216     */
217    public void setCircuitBreakerForceOpen(String circuitBreakerForceOpen) {
218        this.circuitBreakerForceOpen = circuitBreakerForceOpen;
219    }
220
221    public String getCircuitBreakerRequestVolumeThreshold() {
222        return circuitBreakerRequestVolumeThreshold;
223    }
224
225    /**
226     * Minimum number of requests in the
227     * metricsRollingStatisticalWindowInMilliseconds() that must exist before
228     * the HystrixCircuitBreaker will trip.
229     * <p>
230     * If below this number the circuit will not trip regardless of error
231     * percentage.
232     */
233    public void setCircuitBreakerRequestVolumeThreshold(String circuitBreakerRequestVolumeThreshold) {
234        this.circuitBreakerRequestVolumeThreshold = circuitBreakerRequestVolumeThreshold;
235    }
236
237    public String getCircuitBreakerSleepWindowInMilliseconds() {
238        return circuitBreakerSleepWindowInMilliseconds;
239    }
240
241    /**
242     * The time in milliseconds after a HystrixCircuitBreaker trips open that it
243     * should wait before trying requests again.
244     */
245    public void setCircuitBreakerSleepWindowInMilliseconds(String circuitBreakerSleepWindowInMilliseconds) {
246        this.circuitBreakerSleepWindowInMilliseconds = circuitBreakerSleepWindowInMilliseconds;
247    }
248
249    public String getExecutionIsolationSemaphoreMaxConcurrentRequests() {
250        return executionIsolationSemaphoreMaxConcurrentRequests;
251    }
252
253    /**
254     * Number of concurrent requests permitted to HystrixCommand.run(). Requests
255     * beyond the concurrent limit will be rejected.
256     * <p>
257     * Applicable only when executionIsolationStrategy == SEMAPHORE.
258     */
259    public void setExecutionIsolationSemaphoreMaxConcurrentRequests(String executionIsolationSemaphoreMaxConcurrentRequests) {
260        this.executionIsolationSemaphoreMaxConcurrentRequests = executionIsolationSemaphoreMaxConcurrentRequests;
261    }
262
263    public String getExecutionIsolationStrategy() {
264        return executionIsolationStrategy;
265    }
266
267    /**
268     * What isolation strategy HystrixCommand.run() will be executed with.
269     * <p>
270     * If THREAD then it will be executed on a separate thread and concurrent
271     * requests limited by the number of threads in the thread-pool.
272     * <p>
273     * If SEMAPHORE then it will be executed on the calling thread and
274     * concurrent requests limited by the semaphore count.
275     */
276    public void setExecutionIsolationStrategy(String executionIsolationStrategy) {
277        this.executionIsolationStrategy = executionIsolationStrategy;
278    }
279
280    public String getExecutionIsolationThreadInterruptOnTimeout() {
281        return executionIsolationThreadInterruptOnTimeout;
282    }
283
284    /**
285     * Whether the execution thread should attempt an interrupt (using
286     * {@link Future#cancel}) when a thread times out.
287     * <p>
288     * Applicable only when executionIsolationStrategy() == THREAD.
289     */
290    public void setExecutionIsolationThreadInterruptOnTimeout(String executionIsolationThreadInterruptOnTimeout) {
291        this.executionIsolationThreadInterruptOnTimeout = executionIsolationThreadInterruptOnTimeout;
292    }
293
294    public String getExecutionTimeoutInMilliseconds() {
295        return executionTimeoutInMilliseconds;
296    }
297
298    /**
299     * Time in milliseconds at which point the command will timeout and halt
300     * execution.
301     * <p>
302     * If {@link #executionIsolationThreadInterruptOnTimeout} == true and the
303     * command is thread-isolated, the executing thread will be interrupted. If
304     * the command is semaphore-isolated and a HystrixObservableCommand, that
305     * command will get unsubscribed.
306     */
307    public void setExecutionTimeoutInMilliseconds(String executionTimeoutInMilliseconds) {
308        this.executionTimeoutInMilliseconds = executionTimeoutInMilliseconds;
309    }
310
311    public String getExecutionTimeoutEnabled() {
312        return executionTimeoutEnabled;
313    }
314
315    /**
316     * Whether the timeout mechanism is enabled for this command
317     */
318    public void setExecutionTimeoutEnabled(String executionTimeoutEnabled) {
319        this.executionTimeoutEnabled = executionTimeoutEnabled;
320    }
321
322    public String getFallbackIsolationSemaphoreMaxConcurrentRequests() {
323        return fallbackIsolationSemaphoreMaxConcurrentRequests;
324    }
325
326    /**
327     * Number of concurrent requests permitted to HystrixCommand.getFallback().
328     * Requests beyond the concurrent limit will fail-fast and not attempt
329     * retrieving a fallback.
330     */
331    public void setFallbackIsolationSemaphoreMaxConcurrentRequests(String fallbackIsolationSemaphoreMaxConcurrentRequests) {
332        this.fallbackIsolationSemaphoreMaxConcurrentRequests = fallbackIsolationSemaphoreMaxConcurrentRequests;
333    }
334
335    public String getFallbackEnabled() {
336        return fallbackEnabled;
337    }
338
339    /**
340     * Whether HystrixCommand.getFallback() should be attempted when failure
341     * occurs.
342     */
343    public void setFallbackEnabled(String fallbackEnabled) {
344        this.fallbackEnabled = fallbackEnabled;
345    }
346
347    public String getMetricsHealthSnapshotIntervalInMilliseconds() {
348        return metricsHealthSnapshotIntervalInMilliseconds;
349    }
350
351    /**
352     * Time in milliseconds to wait between allowing health snapshots to be
353     * taken that calculate success and error percentages and affect
354     * HystrixCircuitBreaker.isOpen() status.
355     * <p>
356     * On high-volume circuits the continual calculation of error percentage can
357     * become CPU intensive thus this controls how often it is calculated.
358     */
359    public void setMetricsHealthSnapshotIntervalInMilliseconds(String metricsHealthSnapshotIntervalInMilliseconds) {
360        this.metricsHealthSnapshotIntervalInMilliseconds = metricsHealthSnapshotIntervalInMilliseconds;
361    }
362
363    public String getMetricsRollingPercentileBucketSize() {
364        return metricsRollingPercentileBucketSize;
365    }
366
367    /**
368     * Maximum number of values stored in each bucket of the rolling percentile.
369     * This is passed into HystrixRollingPercentile inside
370     * HystrixCommandMetrics.
371     */
372    public void setMetricsRollingPercentileBucketSize(String metricsRollingPercentileBucketSize) {
373        this.metricsRollingPercentileBucketSize = metricsRollingPercentileBucketSize;
374    }
375
376    public String getMetricsRollingPercentileEnabled() {
377        return metricsRollingPercentileEnabled;
378    }
379
380    /**
381     * Whether percentile metrics should be captured using
382     * HystrixRollingPercentile inside HystrixCommandMetrics.
383     */
384    public void setMetricsRollingPercentileEnabled(String metricsRollingPercentileEnabled) {
385        this.metricsRollingPercentileEnabled = metricsRollingPercentileEnabled;
386    }
387
388    public String getMetricsRollingPercentileWindowInMilliseconds() {
389        return metricsRollingPercentileWindowInMilliseconds;
390    }
391
392    /**
393     * Duration of percentile rolling window in milliseconds. This is passed
394     * into HystrixRollingPercentile inside HystrixCommandMetrics.
395     */
396    public void setMetricsRollingPercentileWindowInMilliseconds(String metricsRollingPercentileWindowInMilliseconds) {
397        this.metricsRollingPercentileWindowInMilliseconds = metricsRollingPercentileWindowInMilliseconds;
398    }
399
400    public String getMetricsRollingPercentileWindowBuckets() {
401        return metricsRollingPercentileWindowBuckets;
402    }
403
404    /**
405     * Number of buckets the rolling percentile window is broken into. This is
406     * passed into HystrixRollingPercentile inside HystrixCommandMetrics.
407     */
408    public void setMetricsRollingPercentileWindowBuckets(String metricsRollingPercentileWindowBuckets) {
409        this.metricsRollingPercentileWindowBuckets = metricsRollingPercentileWindowBuckets;
410    }
411
412    public String getMetricsRollingStatisticalWindowInMilliseconds() {
413        return metricsRollingStatisticalWindowInMilliseconds;
414    }
415
416    /**
417     * This property sets the duration of the statistical rolling window, in
418     * milliseconds. This is how long metrics are kept for the thread pool. The
419     * window is divided into buckets and “rolls” by those increments.
420     */
421    public void setMetricsRollingStatisticalWindowInMilliseconds(String metricsRollingStatisticalWindowInMilliseconds) {
422        this.metricsRollingStatisticalWindowInMilliseconds = metricsRollingStatisticalWindowInMilliseconds;
423    }
424
425    public String getMetricsRollingStatisticalWindowBuckets() {
426        return metricsRollingStatisticalWindowBuckets;
427    }
428
429    /**
430     * Number of buckets the rolling statistical window is broken into. This is
431     * passed into HystrixRollingNumber inside HystrixCommandMetrics.
432     */
433    public void setMetricsRollingStatisticalWindowBuckets(String metricsRollingStatisticalWindowBuckets) {
434        this.metricsRollingStatisticalWindowBuckets = metricsRollingStatisticalWindowBuckets;
435    }
436
437    public String getRequestLogEnabled() {
438        return requestLogEnabled;
439    }
440
441    /**
442     * Whether HystrixCommand execution and events should be logged to
443     * HystrixRequestLog.
444     */
445    public void setRequestLogEnabled(String requestLogEnabled) {
446        this.requestLogEnabled = requestLogEnabled;
447    }
448
449    public String getCorePoolSize() {
450        return corePoolSize;
451    }
452
453    /**
454     * Core thread-pool size that gets passed to
455     * {@link java.util.concurrent.ThreadPoolExecutor#setCorePoolSize(int)}
456     */
457    public void setCorePoolSize(String corePoolSize) {
458        this.corePoolSize = corePoolSize;
459    }
460
461    public String getMaximumSize() {
462        return maximumSize;
463    }
464
465    /**
466     * Maximum thread-pool size that gets passed to
467     * {@link ThreadPoolExecutor#setMaximumPoolSize(int)}. This is the maximum
468     * amount of concurrency that can be supported without starting to reject
469     * HystrixCommands. Please note that this setting only takes effect if you
470     * also set allowMaximumSizeToDivergeFromCoreSize
471     */
472    public void setMaximumSize(String maximumSize) {
473        this.maximumSize = maximumSize;
474    }
475
476    public String getKeepAliveTime() {
477        return keepAliveTime;
478    }
479
480    /**
481     * Keep-alive time in minutes that gets passed to
482     * {@link ThreadPoolExecutor#setKeepAliveTime(long, TimeUnit)}
483     */
484    public void setKeepAliveTime(String keepAliveTime) {
485        this.keepAliveTime = keepAliveTime;
486    }
487
488    public String getMaxQueueSize() {
489        return maxQueueSize;
490    }
491
492    /**
493     * Max queue size that gets passed to {@link BlockingQueue} in
494     * HystrixConcurrencyStrategy.getBlockingQueue(int) This should only affect
495     * the instantiation of a threadpool - it is not eliglible to change a queue
496     * size on the fly. For that, use queueSizeRejectionThreshold().
497     */
498    public void setMaxQueueSize(String maxQueueSize) {
499        this.maxQueueSize = maxQueueSize;
500    }
501
502    public String getQueueSizeRejectionThreshold() {
503        return queueSizeRejectionThreshold;
504    }
505
506    /**
507     * Queue size rejection threshold is an artificial "max" size at which
508     * rejections will occur even if {@link #maxQueueSize} has not been reached.
509     * This is done because the {@link #maxQueueSize} of a {@link BlockingQueue}
510     * can not be dynamically changed and we want to support dynamically
511     * changing the queue size that affects rejections.
512     * <p>
513     * This is used by HystrixCommand when queuing a thread for execution.
514     */
515    public void setQueueSizeRejectionThreshold(String queueSizeRejectionThreshold) {
516        this.queueSizeRejectionThreshold = queueSizeRejectionThreshold;
517    }
518
519    public String getThreadPoolRollingNumberStatisticalWindowInMilliseconds() {
520        return threadPoolRollingNumberStatisticalWindowInMilliseconds;
521    }
522
523    /**
524     * Duration of statistical rolling window in milliseconds. This is passed
525     * into HystrixRollingNumber inside each HystrixThreadPoolMetrics instance.
526     */
527    public void setThreadPoolRollingNumberStatisticalWindowInMilliseconds(String threadPoolRollingNumberStatisticalWindowInMilliseconds) {
528        this.threadPoolRollingNumberStatisticalWindowInMilliseconds = threadPoolRollingNumberStatisticalWindowInMilliseconds;
529    }
530
531    public String getThreadPoolRollingNumberStatisticalWindowBuckets() {
532        return threadPoolRollingNumberStatisticalWindowBuckets;
533    }
534
535    /**
536     * Number of buckets the rolling statistical window is broken into. This is
537     * passed into HystrixRollingNumber inside each HystrixThreadPoolMetrics
538     * instance.
539     */
540    public void setThreadPoolRollingNumberStatisticalWindowBuckets(String threadPoolRollingNumberStatisticalWindowBuckets) {
541        this.threadPoolRollingNumberStatisticalWindowBuckets = threadPoolRollingNumberStatisticalWindowBuckets;
542    }
543
544    public String getAllowMaximumSizeToDivergeFromCoreSize() {
545        return allowMaximumSizeToDivergeFromCoreSize;
546    }
547
548    /**
549     * Allows the configuration for maximumSize to take effect. That value can
550     * then be equal to, or higher, than coreSize
551     */
552    public void setAllowMaximumSizeToDivergeFromCoreSize(String allowMaximumSizeToDivergeFromCoreSize) {
553        this.allowMaximumSizeToDivergeFromCoreSize = allowMaximumSizeToDivergeFromCoreSize;
554    }
555}