43
43
* @author Artem Bilan
44
44
* @author Marius Lichtblau
45
45
* @author Anton Aharkau
46
+ * @author Kim Sumin
46
47
*/
47
48
@ SuppressWarnings ("serial" )
48
49
public class ExponentialBackOffPolicy implements SleepingBackOffPolicy <ExponentialBackOffPolicy > {
49
50
50
- protected final Log logger = LogFactory .getLog (this .getClass ());
51
+ protected Log logger = LogFactory .getLog (this .getClass ());
51
52
52
53
/**
53
54
* The default 'initialInterval' value - 100 millisecs. Coupled with the default
@@ -130,6 +131,11 @@ protected void cloneValues(ExponentialBackOffPolicy target) {
130
131
* @param initialInterval the initial interval
131
132
*/
132
133
public void setInitialInterval (long initialInterval ) {
134
+ if (initialInterval < 1 ) {
135
+ logger .warn ("The initial interval value " + initialInterval +
136
+ " is less than 1. " +
137
+ "The initial interval should be at least 1. " );
138
+ }
133
139
this .initialInterval = initialInterval > 1 ? initialInterval : 1 ;
134
140
}
135
141
@@ -139,6 +145,12 @@ public void setInitialInterval(long initialInterval) {
139
145
* @param multiplier the multiplier
140
146
*/
141
147
public void setMultiplier (double multiplier ) {
148
+ if (multiplier <= 1.0 ) {
149
+ logger .warn ("The multiplier value " + multiplier +
150
+ " is less than or equal to 1.0. " +
151
+ "For exponential backoff to work effectively, " +
152
+ "the multiplier should be greater than 1.0. " );
153
+ }
142
154
this .multiplier = multiplier > 1.0 ? multiplier : 1.0 ;
143
155
}
144
156
@@ -150,6 +162,11 @@ public void setMultiplier(double multiplier) {
150
162
* @param maxInterval in milliseconds.
151
163
*/
152
164
public void setMaxInterval (long maxInterval ) {
165
+ if (maxInterval < 1 ) {
166
+ logger .warn ("The max interval value " + maxInterval +
167
+ " is less than or equal to 0. " +
168
+ "The max interval should be positive." );
169
+ }
153
170
this .maxInterval = maxInterval > 0 ? maxInterval : 1 ;
154
171
}
155
172
@@ -252,6 +269,18 @@ public void backOff(BackOffContext backOffContext) throws BackOffInterruptedExce
252
269
}
253
270
}
254
271
272
+ /**
273
+ * Setter for {@link Log}. If not applied the following is used:
274
+ * <p>
275
+ * {@code LogFactory.getLog(getClass())}
276
+ * </p>
277
+ * @param logger the logger the exponential backoff policy uses for logging
278
+ * @since 2.0.x
279
+ */
280
+ public void setLogger (Log logger ) {
281
+ this .logger = logger ;
282
+ }
283
+
255
284
static class ExponentialBackOffContext implements BackOffContext {
256
285
257
286
private final double multiplier ;
0 commit comments