-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
HystrixTimerThreadPoolProperties.java
71 lines (58 loc) · 2.18 KB
/
HystrixTimerThreadPoolProperties.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.netflix.hystrix;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedArchaiusProperty;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy;
import com.netflix.hystrix.strategy.properties.HystrixProperty;
import static com.netflix.hystrix.strategy.properties.HystrixProperty.Factory.asProperty;
/**
* Properties for Hystrix timer thread pool.
* <p>
* Default implementation of methods uses Archaius (https://github.com/Netflix/archaius)
*/
public abstract class HystrixTimerThreadPoolProperties {
private final HystrixProperty<Integer> corePoolSize;
protected HystrixTimerThreadPoolProperties() {
this(new Setter().withCoreSize(Runtime.getRuntime().availableProcessors()));
}
protected HystrixTimerThreadPoolProperties(Setter setter) {
this.corePoolSize = getProperty("hystrix", "coreSize", setter.getCoreSize());
}
private static HystrixProperty<Integer> getProperty(String propertyPrefix, String instanceProperty, Integer defaultValue) {
return asProperty(new HystrixPropertiesChainedArchaiusProperty.IntegerProperty(
new HystrixPropertiesChainedArchaiusProperty.DynamicIntegerProperty(propertyPrefix + ".timer.threadpool.default." + instanceProperty, defaultValue)));
}
public HystrixProperty<Integer> getCorePoolSize() {
return corePoolSize;
}
/**
* Factory method to retrieve the default Setter.
*/
public static Setter Setter() {
return new Setter();
}
/**
* Fluent interface that allows chained setting of properties.
* <p>
* See {@link HystrixPropertiesStrategy} for more information on order of precedence.
* <p>
* Example:
* <p>
* <pre> {@code
* HystrixTimerThreadPoolProperties.Setter()
* .withCoreSize(10);
* } </pre>
*
* @NotThreadSafe
*/
public static class Setter {
private Integer coreSize = null;
private Setter() {
}
public Integer getCoreSize() {
return coreSize;
}
public Setter withCoreSize(int value) {
this.coreSize = value;
return this;
}
}
}