15
15
*/
16
16
package io .github .resilience4j .common .bulkhead .configuration ;
17
17
18
+ import io .github .resilience4j .bulkhead .BulkheadConfig ;
18
19
import io .github .resilience4j .common .utils .ConfigUtils ;
19
20
import io .github .resilience4j .core .ConfigurationNotFoundException ;
20
21
import io .github .resilience4j .core .StringUtils ;
21
22
import io .github .resilience4j .core .lang .Nullable ;
22
- import org .hibernate .validator .constraints .time .DurationMin ;
23
23
24
- import javax .validation .constraints .Min ;
25
24
import java .time .Duration ;
26
25
import java .util .HashMap ;
27
26
import java .util .Map ;
27
+ import java .util .Objects ;
28
28
29
29
public class BulkheadConfigurationProperties {
30
30
31
31
private Map <String , InstanceProperties > instances = new HashMap <>();
32
32
private Map <String , InstanceProperties > configs = new HashMap <>();
33
33
34
- public io . github . resilience4j . bulkhead . BulkheadConfig createBulkheadConfig (InstanceProperties instanceProperties ) {
34
+ public BulkheadConfig createBulkheadConfig (InstanceProperties instanceProperties ) {
35
35
if (StringUtils .isNotEmpty (instanceProperties .getBaseConfig ())) {
36
36
InstanceProperties baseProperties = configs .get (instanceProperties .getBaseConfig ());
37
37
if (baseProperties == null ) {
38
38
throw new ConfigurationNotFoundException (instanceProperties .getBaseConfig ());
39
39
}
40
40
return buildConfigFromBaseConfig (baseProperties , instanceProperties );
41
41
}
42
- return buildBulkheadConfig (io . github . resilience4j . bulkhead . BulkheadConfig .custom (), instanceProperties );
42
+ return buildBulkheadConfig (BulkheadConfig .custom (), instanceProperties );
43
43
}
44
44
45
- private io . github . resilience4j . bulkhead . BulkheadConfig buildConfigFromBaseConfig (InstanceProperties baseProperties , InstanceProperties instanceProperties ) {
45
+ private BulkheadConfig buildConfigFromBaseConfig (InstanceProperties baseProperties , InstanceProperties instanceProperties ) {
46
46
ConfigUtils .mergePropertiesIfAny (baseProperties , instanceProperties );
47
- io . github . resilience4j . bulkhead . BulkheadConfig baseConfig = buildBulkheadConfig (io . github . resilience4j . bulkhead . BulkheadConfig .custom (), baseProperties );
48
- return buildBulkheadConfig (io . github . resilience4j . bulkhead . BulkheadConfig .from (baseConfig ), instanceProperties );
47
+ BulkheadConfig baseConfig = buildBulkheadConfig (BulkheadConfig .custom (), baseProperties );
48
+ return buildBulkheadConfig (BulkheadConfig .from (baseConfig ), instanceProperties );
49
49
}
50
50
51
- private io . github . resilience4j . bulkhead . BulkheadConfig buildBulkheadConfig (io . github . resilience4j . bulkhead . BulkheadConfig .Builder builder , InstanceProperties instanceProperties ) {
51
+ private BulkheadConfig buildBulkheadConfig (BulkheadConfig .Builder builder , InstanceProperties instanceProperties ) {
52
52
if (instanceProperties .getMaxConcurrentCalls () != null ) {
53
53
builder .maxConcurrentCalls (instanceProperties .getMaxConcurrentCalls ());
54
54
}
@@ -84,23 +84,30 @@ public Map<String, InstanceProperties> getConfigs() {
84
84
*/
85
85
public static class InstanceProperties {
86
86
87
- @ Min (1 )
88
87
private Integer maxConcurrentCalls ;
89
- @ DurationMin (millis = 0 )
90
- private Duration maxWaitDuration ;
91
- @ Nullable
92
- private String baseConfig ;
93
- @ Min (1 )
94
- @ Nullable
95
- private Integer eventConsumerBufferSize ;
88
+ private Duration maxWaitDuration ;
89
+ @ Nullable
90
+ private String baseConfig ;
91
+ @ Nullable
92
+ private Integer eventConsumerBufferSize ;
96
93
97
94
public InstanceProperties setMaxConcurrentCalls (Integer maxConcurrentCalls ) {
95
+ Objects .requireNonNull (maxConcurrentCalls );
96
+ if (maxConcurrentCalls < 1 ) {
97
+ throw new IllegalArgumentException ("maxConcurrentCalls must be greater than or equal to 1." );
98
+ }
99
+
98
100
this .maxConcurrentCalls = maxConcurrentCalls ;
99
101
return this ;
100
102
}
101
103
102
104
public InstanceProperties setMaxWaitDuration (Duration maxWaitDuration ) {
103
- this .maxWaitDuration = maxWaitDuration ;
105
+ Objects .requireNonNull (maxWaitDuration );
106
+ if (maxWaitDuration .toMillis () < 0 ) {
107
+ throw new IllegalArgumentException ("maxWaitDuration must be greater than or equal to 0." );
108
+ }
109
+
110
+ this .maxWaitDuration = maxWaitDuration ;
104
111
return this ;
105
112
}
106
113
@@ -110,7 +117,12 @@ public InstanceProperties setBaseConfig(String baseConfig) {
110
117
}
111
118
112
119
public InstanceProperties setEventConsumerBufferSize (Integer eventConsumerBufferSize ) {
113
- this .eventConsumerBufferSize = eventConsumerBufferSize ;
120
+ Objects .requireNonNull (eventConsumerBufferSize );
121
+ if (eventConsumerBufferSize < 1 ) {
122
+ throw new IllegalArgumentException ("eventConsumerBufferSize must be greater than or equal to 1." );
123
+ }
124
+
125
+ this .eventConsumerBufferSize = eventConsumerBufferSize ;
114
126
return this ;
115
127
}
116
128
@@ -122,10 +134,12 @@ public Duration getMaxWaitDuration() {
122
134
return maxWaitDuration ;
123
135
}
124
136
137
+ @ Nullable
125
138
public String getBaseConfig () {
126
139
return baseConfig ;
127
140
}
128
141
142
+ @ Nullable
129
143
public Integer getEventConsumerBufferSize () {
130
144
return eventConsumerBufferSize ;
131
145
}
0 commit comments