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;
023import javax.xml.bind.annotation.XmlAccessType;
024import javax.xml.bind.annotation.XmlAccessorType;
025import javax.xml.bind.annotation.XmlAttribute;
026import javax.xml.bind.annotation.XmlRootElement;
027import javax.xml.bind.annotation.XmlTransient;
028
029import org.apache.camel.spi.Metadata;
030
031/**
032 * Hystrix Circuit Breaker EIP configuration
033 */
034@Metadata(label = "eip,routing,circuitbreaker")
035@XmlRootElement(name = "hystrixConfiguration")
036@XmlAccessorType(XmlAccessType.FIELD)
037public class HystrixConfigurationDefinition extends IdentifiedType {
038
039    public static final String DEFAULT_GROUP_KEY = "CamelHystrix";
040
041    @XmlTransient
042    private HystrixDefinition parent;
043    @XmlAttribute @Metadata(defaultValue = "CamelHystrix")
044    private String groupKey;
045    @XmlAttribute @Metadata(defaultValue = "CamelHystrix")
046    private String threadPoolKey;
047    @XmlAttribute
048    @Metadata(label = "command", defaultValue = "true")
049    private Boolean circuitBreakerEnabled;
050    @XmlAttribute
051    @Metadata(label = "command", defaultValue = "50")
052    private Integer circuitBreakerErrorThresholdPercentage;
053    @XmlAttribute
054    @Metadata(label = "command", defaultValue = "true")
055    private Boolean circuitBreakerForceClosed;
056    @XmlAttribute
057    @Metadata(label = "command", defaultValue = "false")
058    private Boolean circuitBreakerForceOpen;
059    @XmlAttribute
060    @Metadata(label = "command", defaultValue = "20")
061    private Integer circuitBreakerRequestVolumeThreshold;
062    @XmlAttribute
063    @Metadata(label = "command", defaultValue = "5000")
064    private Integer circuitBreakerSleepWindowInMilliseconds;
065    @XmlAttribute
066    @Metadata(label = "command", defaultValue = "20")
067    private Integer executionIsolationSemaphoreMaxConcurrentRequests;
068    @XmlAttribute
069    @Metadata(label = "command", defaultValue = "THREAD")
070    private String executionIsolationStrategy;
071    @XmlAttribute
072    @Metadata(label = "command", defaultValue = "true")
073    private Boolean executionIsolationThreadInterruptOnTimeout;
074    @XmlAttribute
075    @Metadata(label = "command", defaultValue = "1000")
076    private Integer executionTimeoutInMilliseconds;
077    @XmlAttribute
078    @Metadata(label = "command", defaultValue = "true")
079    private Boolean executionTimeoutEnabled;
080    @XmlAttribute
081    @Metadata(label = "command", defaultValue = "10")
082    private Integer fallbackIsolationSemaphoreMaxConcurrentRequests;
083    @XmlAttribute
084    @Metadata(label = "command", defaultValue = "true")
085    private Boolean fallbackEnabled;
086    @XmlAttribute
087    @Metadata(label = "command", defaultValue = "500")
088    private Integer metricsHealthSnapshotIntervalInMilliseconds;
089    @XmlAttribute
090    @Metadata(label = "command", defaultValue = "10")
091    private Integer metricsRollingPercentileBucketSize;
092    @XmlAttribute
093    @Metadata(label = "command", defaultValue = "true")
094    private Boolean metricsRollingPercentileEnabled;
095    @XmlAttribute
096    @Metadata(label = "command", defaultValue = "false")
097    private Integer metricsRollingPercentileWindowInMilliseconds;
098    @XmlAttribute
099    @Metadata(label = "command", defaultValue = "6")
100    private Integer metricsRollingPercentileWindowBuckets;
101    @XmlAttribute
102    @Metadata(label = "command", defaultValue = "10000")
103    private Integer metricsRollingStatisticalWindowInMilliseconds;
104    @XmlAttribute
105    @Metadata(label = "command", defaultValue = "10")
106    private Integer metricsRollingStatisticalWindowBuckets;
107    @XmlAttribute
108    @Metadata(label = "command", defaultValue = "true")
109    private Boolean requestLogEnabled;
110
111    // thread-pool
112
113    @XmlAttribute
114    @Metadata(label = "threadpool", defaultValue = "10")
115    private Integer corePoolSize;
116    @XmlAttribute
117    @Metadata(label = "threadpool", defaultValue = "1")
118    private Integer keepAliveTime;
119    @XmlAttribute
120    @Metadata(label = "threadpool", defaultValue = "-1")
121    private Integer maxQueueSize;
122    @XmlAttribute
123    @Metadata(label = "threadpool", defaultValue = "5")
124    private Integer queueSizeRejectionThreshold;
125    @XmlAttribute
126    @Metadata(label = "threadpool", defaultValue = "10000")
127    private Integer threadPoolRollingNumberStatisticalWindowInMilliseconds;
128    @XmlAttribute
129    @Metadata(label = "threadpool", defaultValue = "10")
130    private Integer threadPoolRollingNumberStatisticalWindowBuckets;
131
132    public HystrixConfigurationDefinition() {
133    }
134
135    public HystrixConfigurationDefinition(HystrixDefinition parent) {
136        this.parent = parent;
137    }
138
139    // Getter/Setter
140    // -------------------------------------------------------------------------
141
142    public String getGroupKey() {
143        return groupKey;
144    }
145
146    public void setGroupKey(String groupKey) {
147        this.groupKey = groupKey;
148    }
149
150    public String getThreadPoolKey() {
151        return threadPoolKey;
152    }
153
154    public void setThreadPoolKey(String threadPoolKey) {
155        this.threadPoolKey = threadPoolKey;
156    }
157
158    public Boolean getCircuitBreakerEnabled() {
159        return circuitBreakerEnabled;
160    }
161
162    public void setCircuitBreakerEnabled(Boolean circuitBreakerEnabled) {
163        this.circuitBreakerEnabled = circuitBreakerEnabled;
164    }
165
166    public Integer getCircuitBreakerErrorThresholdPercentage() {
167        return circuitBreakerErrorThresholdPercentage;
168    }
169
170    public void setCircuitBreakerErrorThresholdPercentage(Integer circuitBreakerErrorThresholdPercentage) {
171        this.circuitBreakerErrorThresholdPercentage = circuitBreakerErrorThresholdPercentage;
172    }
173
174    public Boolean getCircuitBreakerForceClosed() {
175        return circuitBreakerForceClosed;
176    }
177
178    public void setCircuitBreakerForceClosed(Boolean circuitBreakerForceClosed) {
179        this.circuitBreakerForceClosed = circuitBreakerForceClosed;
180    }
181
182    public Boolean getCircuitBreakerForceOpen() {
183        return circuitBreakerForceOpen;
184    }
185
186    public void setCircuitBreakerForceOpen(Boolean circuitBreakerForceOpen) {
187        this.circuitBreakerForceOpen = circuitBreakerForceOpen;
188    }
189
190    public Integer getCircuitBreakerRequestVolumeThreshold() {
191        return circuitBreakerRequestVolumeThreshold;
192    }
193
194    public void setCircuitBreakerRequestVolumeThreshold(Integer circuitBreakerRequestVolumeThreshold) {
195        this.circuitBreakerRequestVolumeThreshold = circuitBreakerRequestVolumeThreshold;
196    }
197
198    public Integer getCircuitBreakerSleepWindowInMilliseconds() {
199        return circuitBreakerSleepWindowInMilliseconds;
200    }
201
202    public void setCircuitBreakerSleepWindowInMilliseconds(Integer circuitBreakerSleepWindowInMilliseconds) {
203        this.circuitBreakerSleepWindowInMilliseconds = circuitBreakerSleepWindowInMilliseconds;
204    }
205
206    public Integer getExecutionIsolationSemaphoreMaxConcurrentRequests() {
207        return executionIsolationSemaphoreMaxConcurrentRequests;
208    }
209
210    public void setExecutionIsolationSemaphoreMaxConcurrentRequests(Integer executionIsolationSemaphoreMaxConcurrentRequests) {
211        this.executionIsolationSemaphoreMaxConcurrentRequests = executionIsolationSemaphoreMaxConcurrentRequests;
212    }
213
214    public String getExecutionIsolationStrategy() {
215        return executionIsolationStrategy;
216    }
217
218    public void setExecutionIsolationStrategy(String executionIsolationStrategy) {
219        this.executionIsolationStrategy = executionIsolationStrategy;
220    }
221
222    public Boolean getExecutionIsolationThreadInterruptOnTimeout() {
223        return executionIsolationThreadInterruptOnTimeout;
224    }
225
226    public void setExecutionIsolationThreadInterruptOnTimeout(Boolean executionIsolationThreadInterruptOnTimeout) {
227        this.executionIsolationThreadInterruptOnTimeout = executionIsolationThreadInterruptOnTimeout;
228    }
229
230    public Integer getExecutionTimeoutInMilliseconds() {
231        return executionTimeoutInMilliseconds;
232    }
233
234    public void setExecutionTimeoutInMilliseconds(Integer executionTimeoutInMilliseconds) {
235        this.executionTimeoutInMilliseconds = executionTimeoutInMilliseconds;
236    }
237
238    public Boolean getExecutionTimeoutEnabled() {
239        return executionTimeoutEnabled;
240    }
241
242    public void setExecutionTimeoutEnabled(Boolean executionTimeoutEnabled) {
243        this.executionTimeoutEnabled = executionTimeoutEnabled;
244    }
245
246    public Integer getFallbackIsolationSemaphoreMaxConcurrentRequests() {
247        return fallbackIsolationSemaphoreMaxConcurrentRequests;
248    }
249
250    public void setFallbackIsolationSemaphoreMaxConcurrentRequests(Integer fallbackIsolationSemaphoreMaxConcurrentRequests) {
251        this.fallbackIsolationSemaphoreMaxConcurrentRequests = fallbackIsolationSemaphoreMaxConcurrentRequests;
252    }
253
254    public Boolean getFallbackEnabled() {
255        return fallbackEnabled;
256    }
257
258    public void setFallbackEnabled(Boolean fallbackEnabled) {
259        this.fallbackEnabled = fallbackEnabled;
260    }
261
262    public Integer getMetricsHealthSnapshotIntervalInMilliseconds() {
263        return metricsHealthSnapshotIntervalInMilliseconds;
264    }
265
266    public void setMetricsHealthSnapshotIntervalInMilliseconds(Integer metricsHealthSnapshotIntervalInMilliseconds) {
267        this.metricsHealthSnapshotIntervalInMilliseconds = metricsHealthSnapshotIntervalInMilliseconds;
268    }
269
270    public Integer getMetricsRollingPercentileBucketSize() {
271        return metricsRollingPercentileBucketSize;
272    }
273
274    public void setMetricsRollingPercentileBucketSize(Integer metricsRollingPercentileBucketSize) {
275        this.metricsRollingPercentileBucketSize = metricsRollingPercentileBucketSize;
276    }
277
278    public Boolean getMetricsRollingPercentileEnabled() {
279        return metricsRollingPercentileEnabled;
280    }
281
282    public void setMetricsRollingPercentileEnabled(Boolean metricsRollingPercentileEnabled) {
283        this.metricsRollingPercentileEnabled = metricsRollingPercentileEnabled;
284    }
285
286    public Integer getMetricsRollingPercentileWindowInMilliseconds() {
287        return metricsRollingPercentileWindowInMilliseconds;
288    }
289
290    public void setMetricsRollingPercentileWindowInMilliseconds(Integer metricsRollingPercentileWindowInMilliseconds) {
291        this.metricsRollingPercentileWindowInMilliseconds = metricsRollingPercentileWindowInMilliseconds;
292    }
293
294    public Integer getMetricsRollingPercentileWindowBuckets() {
295        return metricsRollingPercentileWindowBuckets;
296    }
297
298    public void setMetricsRollingPercentileWindowBuckets(Integer metricsRollingPercentileWindowBuckets) {
299        this.metricsRollingPercentileWindowBuckets = metricsRollingPercentileWindowBuckets;
300    }
301
302    public Integer getMetricsRollingStatisticalWindowInMilliseconds() {
303        return metricsRollingStatisticalWindowInMilliseconds;
304    }
305
306    public void setMetricsRollingStatisticalWindowInMilliseconds(Integer metricsRollingStatisticalWindowInMilliseconds) {
307        this.metricsRollingStatisticalWindowInMilliseconds = metricsRollingStatisticalWindowInMilliseconds;
308    }
309
310    public Integer getMetricsRollingStatisticalWindowBuckets() {
311        return metricsRollingStatisticalWindowBuckets;
312    }
313
314    public void setMetricsRollingStatisticalWindowBuckets(Integer metricsRollingStatisticalWindowBuckets) {
315        this.metricsRollingStatisticalWindowBuckets = metricsRollingStatisticalWindowBuckets;
316    }
317
318    public Boolean getRequestLogEnabled() {
319        return requestLogEnabled;
320    }
321
322    public void setRequestLogEnabled(Boolean requestLogEnabled) {
323        this.requestLogEnabled = requestLogEnabled;
324    }
325
326    public Integer getCorePoolSize() {
327        return corePoolSize;
328    }
329
330    public void setCorePoolSize(Integer corePoolSize) {
331        this.corePoolSize = corePoolSize;
332    }
333
334    public Integer getKeepAliveTime() {
335        return keepAliveTime;
336    }
337
338    public void setKeepAliveTime(Integer keepAliveTime) {
339        this.keepAliveTime = keepAliveTime;
340    }
341
342    public Integer getMaxQueueSize() {
343        return maxQueueSize;
344    }
345
346    public void setMaxQueueSize(Integer maxQueueSize) {
347        this.maxQueueSize = maxQueueSize;
348    }
349
350    public Integer getQueueSizeRejectionThreshold() {
351        return queueSizeRejectionThreshold;
352    }
353
354    public void setQueueSizeRejectionThreshold(Integer queueSizeRejectionThreshold) {
355        this.queueSizeRejectionThreshold = queueSizeRejectionThreshold;
356    }
357
358    public Integer getThreadPoolRollingNumberStatisticalWindowInMilliseconds() {
359        return threadPoolRollingNumberStatisticalWindowInMilliseconds;
360    }
361
362    public void setThreadPoolRollingNumberStatisticalWindowInMilliseconds(Integer threadPoolRollingNumberStatisticalWindowInMilliseconds) {
363        this.threadPoolRollingNumberStatisticalWindowInMilliseconds = threadPoolRollingNumberStatisticalWindowInMilliseconds;
364    }
365
366    public Integer getThreadPoolRollingNumberStatisticalWindowBuckets() {
367        return threadPoolRollingNumberStatisticalWindowBuckets;
368    }
369
370    public void setThreadPoolRollingNumberStatisticalWindowBuckets(Integer threadPoolRollingNumberStatisticalWindowBuckets) {
371        this.threadPoolRollingNumberStatisticalWindowBuckets = threadPoolRollingNumberStatisticalWindowBuckets;
372    }
373
374
375    // Fluent API
376    // -------------------------------------------------------------------------
377
378    /**
379     * Sets the group key to use. The default value is CamelHystrix.
380     */
381    public HystrixConfigurationDefinition groupKey(String groupKey) {
382        setGroupKey(groupKey);
383        return this;
384    }
385
386    /**
387     * Sets the thread pool key to use. Will by default use the same value as groupKey has been configured to use.
388     */
389    public HystrixConfigurationDefinition threadPoolKey(String threadPoolKey) {
390        setThreadPoolKey(threadPoolKey);
391        return this;
392    }
393
394    /**
395     * Whether to use a HystrixCircuitBreaker or not. If false no circuit-breaker logic will be used and all requests permitted.
396     * <p>
397     * This is similar in effect to circuitBreakerForceClosed() except that continues tracking metrics and knowing whether it
398     * should be open/closed, this property results in not even instantiating a circuit-breaker.
399     */
400    public HystrixConfigurationDefinition circuitBreakerEnabled(Boolean circuitBreakerEnabled) {
401        this.circuitBreakerEnabled = circuitBreakerEnabled;
402        return this;
403    }
404
405    /**
406     * Error percentage threshold (as whole number such as 50) at which point the circuit breaker will trip open and reject requests.
407     * <p>
408     * It will stay tripped for the duration defined in circuitBreakerSleepWindowInMilliseconds;
409     * <p>
410     * The error percentage this is compared against comes from HystrixCommandMetrics.getHealthCounts().
411     */
412    public HystrixConfigurationDefinition circuitBreakerErrorThresholdPercentage(Integer circuitBreakerErrorThresholdPercentage) {
413        this.circuitBreakerErrorThresholdPercentage = circuitBreakerErrorThresholdPercentage;
414        return this;
415    }
416
417    /**
418     * If true the HystrixCircuitBreaker#allowRequest() will always return true to allow requests regardless of
419     * the error percentage from HystrixCommandMetrics.getHealthCounts().
420     * <p>
421     * The circuitBreakerForceOpen() property takes precedence so if it set to true this property does nothing.
422     */
423    public HystrixConfigurationDefinition circuitBreakerForceClosed(Boolean circuitBreakerForceClosed) {
424        this.circuitBreakerForceClosed = circuitBreakerForceClosed;
425        return this;
426    }
427
428    /**
429     * If true the HystrixCircuitBreaker.allowRequest() will always return false, causing the circuit to be open (tripped) and reject all requests.
430     * <p>
431     * This property takes precedence over circuitBreakerForceClosed();
432     */
433    public HystrixConfigurationDefinition circuitBreakerForceOpen(Boolean circuitBreakerForceOpen) {
434        this.circuitBreakerForceOpen = circuitBreakerForceOpen;
435        return this;
436    }
437
438    /**
439     * Minimum number of requests in the metricsRollingStatisticalWindowInMilliseconds() that must exist before the HystrixCircuitBreaker will trip.
440     * <p>
441     * If below this number the circuit will not trip regardless of error percentage.
442     */
443    public HystrixConfigurationDefinition circuitBreakerRequestVolumeThreshold(Integer circuitBreakerRequestVolumeThreshold) {
444        this.circuitBreakerRequestVolumeThreshold = circuitBreakerRequestVolumeThreshold;
445        return this;
446    }
447
448    /**
449     * The time in milliseconds after a HystrixCircuitBreaker trips open that it should wait before trying requests again.
450     */
451    public HystrixConfigurationDefinition circuitBreakerSleepWindowInMilliseconds(Integer circuitBreakerSleepWindowInMilliseconds) {
452        this.circuitBreakerSleepWindowInMilliseconds = circuitBreakerSleepWindowInMilliseconds;
453        return this;
454    }
455
456    /**
457     * Number of concurrent requests permitted to HystrixCommand.run(). Requests beyond the concurrent limit will be rejected.
458     * <p>
459     * Applicable only when executionIsolationStrategy == SEMAPHORE.
460     */
461    public HystrixConfigurationDefinition executionIsolationSemaphoreMaxConcurrentRequests(Integer executionIsolationSemaphoreMaxConcurrentRequests) {
462        this.executionIsolationSemaphoreMaxConcurrentRequests = executionIsolationSemaphoreMaxConcurrentRequests;
463        return this;
464    }
465
466    /**
467     * What isolation strategy HystrixCommand.run() will be executed with.
468     * <p>
469     * If THREAD then it will be executed on a separate thread and concurrent requests limited by the number of threads in the thread-pool.
470     * <p>
471     * If SEMAPHORE then it will be executed on the calling thread and concurrent requests limited by the semaphore count.
472     */
473    public HystrixConfigurationDefinition executionIsolationStrategy(String executionIsolationStrategy) {
474        this.executionIsolationStrategy = executionIsolationStrategy;
475        return this;
476    }
477
478    /**
479     * Whether the execution thread should attempt an interrupt (using {@link Future#cancel}) when a thread times out.
480     * <p>
481     * Applicable only when executionIsolationStrategy() == THREAD.
482     */
483    public HystrixConfigurationDefinition executionIsolationThreadInterruptOnTimeout(Boolean executionIsolationThreadInterruptOnTimeout) {
484        this.executionIsolationThreadInterruptOnTimeout = executionIsolationThreadInterruptOnTimeout;
485        return this;
486    }
487
488    /**
489     * Time in milliseconds at which point the command will timeout and halt execution.
490     * <p>
491     * If {@link #executionIsolationThreadInterruptOnTimeout} == true and the command is thread-isolated, the executing thread will be interrupted.
492     * If the command is semaphore-isolated and a HystrixObservableCommand, that command will get unsubscribed.
493     */
494    public HystrixConfigurationDefinition executionTimeoutInMilliseconds(Integer executionTimeoutInMilliseconds) {
495        this.executionTimeoutInMilliseconds = executionTimeoutInMilliseconds;
496        return this;
497    }
498
499    /**
500     * Whether the timeout mechanism is enabled for this command
501     */
502    public HystrixConfigurationDefinition executionTimeoutEnabled(Boolean executionTimeoutEnabled) {
503        this.executionTimeoutEnabled = executionTimeoutEnabled;
504        return this;
505    }
506
507    /**
508     * Number of concurrent requests permitted to HystrixCommand.getFallback().
509     * Requests beyond the concurrent limit will fail-fast and not attempt retrieving a fallback.
510     */
511    public HystrixConfigurationDefinition fallbackIsolationSemaphoreMaxConcurrentRequests(Integer fallbackIsolationSemaphoreMaxConcurrentRequests) {
512        this.fallbackIsolationSemaphoreMaxConcurrentRequests = fallbackIsolationSemaphoreMaxConcurrentRequests;
513        return this;
514    }
515
516    /**
517     * Whether HystrixCommand.getFallback() should be attempted when failure occurs.
518     */
519    public HystrixConfigurationDefinition fallbackEnabled(Boolean fallbackEnabled) {
520        this.fallbackEnabled = fallbackEnabled;
521        return this;
522    }
523
524    /**
525     * Time in milliseconds to wait between allowing health snapshots to be taken that calculate success and error
526     * percentages and affect HystrixCircuitBreaker.isOpen() status.
527     * <p>
528     * On high-volume circuits the continual calculation of error percentage can become CPU intensive thus this controls how often it is calculated.
529     */
530    public HystrixConfigurationDefinition metricsHealthSnapshotIntervalInMilliseconds(Integer metricsHealthSnapshotIntervalInMilliseconds) {
531        this.metricsHealthSnapshotIntervalInMilliseconds = metricsHealthSnapshotIntervalInMilliseconds;
532        return this;
533    }
534
535    /**
536     * Maximum number of values stored in each bucket of the rolling percentile.
537     * This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.
538     */
539    public HystrixConfigurationDefinition metricsRollingPercentileBucketSize(Integer metricsRollingPercentileBucketSize) {
540        this.metricsRollingPercentileBucketSize = metricsRollingPercentileBucketSize;
541        return this;
542    }
543
544    /**
545     * Whether percentile metrics should be captured using HystrixRollingPercentile inside HystrixCommandMetrics.
546     */
547    public HystrixConfigurationDefinition metricsRollingPercentileEnabled(Boolean metricsRollingPercentileEnabled) {
548        this.metricsRollingPercentileEnabled = metricsRollingPercentileEnabled;
549        return this;
550    }
551
552    /**
553     * Duration of percentile rolling window in milliseconds.
554     * This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.
555     */
556    public HystrixConfigurationDefinition metricsRollingPercentileWindowInMilliseconds(Integer metricsRollingPercentileWindowInMilliseconds) {
557        this.metricsRollingPercentileWindowInMilliseconds = metricsRollingPercentileWindowInMilliseconds;
558        return this;
559    }
560
561    /**
562     * Number of buckets the rolling percentile window is broken into.
563     * This is passed into HystrixRollingPercentile inside HystrixCommandMetrics.
564     */
565    public HystrixConfigurationDefinition metricsRollingPercentileWindowBuckets(Integer metricsRollingPercentileWindowBuckets) {
566        this.metricsRollingPercentileWindowBuckets = metricsRollingPercentileWindowBuckets;
567        return this;
568    }
569
570    /**
571     * Duration of statistical rolling window in milliseconds.
572     * This is passed into HystrixRollingNumber inside HystrixCommandMetrics.
573     */
574    public HystrixConfigurationDefinition metricsRollingStatisticalWindowInMilliseconds(Integer metricsRollingStatisticalWindowInMilliseconds) {
575        this.metricsRollingStatisticalWindowInMilliseconds = metricsRollingStatisticalWindowInMilliseconds;
576        return this;
577    }
578
579    /**
580     * Number of buckets the rolling statistical window is broken into.
581     * This is passed into HystrixRollingNumber inside HystrixCommandMetrics.
582     */
583    public HystrixConfigurationDefinition metricsRollingStatisticalWindowBuckets(Integer metricsRollingStatisticalWindowBuckets) {
584        this.metricsRollingStatisticalWindowBuckets = metricsRollingStatisticalWindowBuckets;
585        return this;
586    }
587
588    /**
589     * Whether HystrixCommand execution and events should be logged to HystrixRequestLog.
590     */
591    public HystrixConfigurationDefinition requestLogEnabled(Boolean requestLogEnabled) {
592        this.requestLogEnabled = requestLogEnabled;
593        return this;
594    }
595
596    /**
597     * Core thread-pool size that gets passed to {@link java.util.concurrent.ThreadPoolExecutor#setCorePoolSize(int)}
598     */
599    public HystrixConfigurationDefinition corePoolSize(Integer corePoolSize) {
600        this.corePoolSize = corePoolSize;
601        return this;
602    }
603
604    /**
605     * Keep-alive time in minutes that gets passed to {@link ThreadPoolExecutor#setKeepAliveTime(long, TimeUnit)}
606     */
607    public HystrixConfigurationDefinition keepAliveTime(Integer keepAliveTime) {
608        this.keepAliveTime = keepAliveTime;
609        return this;
610    }
611
612    /**
613     * Max queue size that gets passed to {@link BlockingQueue} in HystrixConcurrencyStrategy.getBlockingQueue(int)
614     *
615     * This should only affect the instantiation of a threadpool - it is not eliglible to change a queue size on the fly.
616     * For that, use queueSizeRejectionThreshold().
617     */
618    public HystrixConfigurationDefinition maxQueueSize(Integer maxQueueSize) {
619        this.maxQueueSize = maxQueueSize;
620        return this;
621    }
622
623    /**
624     * Queue size rejection threshold is an artificial "max" size at which rejections will occur even
625     * if {@link #maxQueueSize} has not been reached. This is done because the {@link #maxQueueSize}
626     * of a {@link BlockingQueue} can not be dynamically changed and we want to support dynamically
627     * changing the queue size that affects rejections.
628     * <p>
629     * This is used by HystrixCommand when queuing a thread for execution.
630     */
631    public HystrixConfigurationDefinition queueSizeRejectionThreshold(Integer queueSizeRejectionThreshold) {
632        this.queueSizeRejectionThreshold = queueSizeRejectionThreshold;
633        return this;
634    }
635
636    /**
637     * Duration of statistical rolling window in milliseconds.
638     * This is passed into HystrixRollingNumber inside each HystrixThreadPoolMetrics instance.
639     */
640    public HystrixConfigurationDefinition threadPoolRollingNumberStatisticalWindowInMilliseconds(Integer threadPoolRollingNumberStatisticalWindowInMilliseconds) {
641        this.threadPoolRollingNumberStatisticalWindowInMilliseconds = threadPoolRollingNumberStatisticalWindowInMilliseconds;
642        return this;
643    }
644
645    /**
646     * Number of buckets the rolling statistical window is broken into.
647     * This is passed into HystrixRollingNumber inside each HystrixThreadPoolMetrics instance.
648     */
649    public HystrixConfigurationDefinition threadPoolRollingNumberStatisticalWindowBuckets(Integer threadPoolRollingNumberStatisticalWindowBuckets) {
650        this.threadPoolRollingNumberStatisticalWindowBuckets = threadPoolRollingNumberStatisticalWindowBuckets;
651        return this;
652    }
653
654    /**
655     * End of configuration
656     */
657    public HystrixDefinition end() {
658        return parent;
659    }
660
661}