1
1
/*
2
- * Copyright 2002-2020 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
21
21
/**
22
22
* Implementation of {@link BackOff} that increases the back off period for each
23
- * retry attempt. When the interval has reached the {@link #setMaxInterval(long)
23
+ * retry attempt. When the interval has reached the {@linkplain #setMaxInterval
24
24
* max interval}, it is no longer increased. Stops retrying once the
25
- * {@link #setMaxElapsedTime(long) max elapsed time} has been reached.
25
+ * {@linkplain #setMaxElapsedTime max elapsed time} has been reached.
26
26
*
27
- * <p>Example: The default interval is {@value #DEFAULT_INITIAL_INTERVAL} ms,
28
- * the default multiplier is {@value #DEFAULT_MULTIPLIER}, and the default max
27
+ * <p>Example: The default interval is {@value #DEFAULT_INITIAL_INTERVAL} ms;
28
+ * the default multiplier is {@value #DEFAULT_MULTIPLIER}; and the default max
29
29
* interval is {@value #DEFAULT_MAX_INTERVAL}. For 10 attempts the sequence will be
30
30
* as follows:
31
31
*
44
44
* 10 30000
45
45
* </pre>
46
46
*
47
- * <p>Note that the default max elapsed time is {@link Long#MAX_VALUE}. Use
48
- * {@link #setMaxElapsedTime(long)} to limit the maximum length of time
49
- * that an instance should accumulate before returning
50
- * {@link BackOffExecution#STOP}.
47
+ * <p>Note that the default max elapsed time is {@link Long#MAX_VALUE}.
48
+ * Use {@link #setMaxElapsedTime} to limit the maximum length of time that an
49
+ * instance should accumulate before returning {@link BackOffExecution#STOP}.
51
50
*
52
51
* @author Stephane Nicoll
53
52
* @since 4.1
@@ -107,7 +106,7 @@ public ExponentialBackOff(long initialInterval, double multiplier) {
107
106
108
107
109
108
/**
110
- * The initial interval in milliseconds.
109
+ * Set the initial interval in milliseconds.
111
110
*/
112
111
public void setInitialInterval (long initialInterval ) {
113
112
this .initialInterval = initialInterval ;
@@ -121,7 +120,7 @@ public long getInitialInterval() {
121
120
}
122
121
123
122
/**
124
- * The value to multiply the current interval by for each retry attempt.
123
+ * Set the value to multiply the current interval by for each retry attempt.
125
124
*/
126
125
public void setMultiplier (double multiplier ) {
127
126
checkMultiplier (multiplier );
@@ -136,21 +135,21 @@ public double getMultiplier() {
136
135
}
137
136
138
137
/**
139
- * The maximum back off time.
138
+ * Set the maximum back off time in milliseconds .
140
139
*/
141
140
public void setMaxInterval (long maxInterval ) {
142
141
this .maxInterval = maxInterval ;
143
142
}
144
143
145
144
/**
146
- * Return the maximum back off time.
145
+ * Return the maximum back off time in milliseconds .
147
146
*/
148
147
public long getMaxInterval () {
149
148
return this .maxInterval ;
150
149
}
151
150
152
151
/**
153
- * The maximum elapsed time in milliseconds after which a call to
152
+ * Set the maximum elapsed time in milliseconds after which a call to
154
153
* {@link BackOffExecution#nextBackOff()} returns {@link BackOffExecution#STOP}.
155
154
*/
156
155
public void setMaxElapsedTime (long maxElapsedTime ) {
@@ -184,10 +183,9 @@ private class ExponentialBackOffExecution implements BackOffExecution {
184
183
185
184
@ Override
186
185
public long nextBackOff () {
187
- if (this .currentElapsedTime >= maxElapsedTime ) {
186
+ if (this .currentElapsedTime >= getMaxElapsedTime () ) {
188
187
return STOP ;
189
188
}
190
-
191
189
long nextInterval = computeNextInterval ();
192
190
this .currentElapsedTime += nextInterval ;
193
191
return nextInterval ;
@@ -214,7 +212,6 @@ private long multiplyInterval(long maxInterval) {
214
212
return Math .min (i , maxInterval );
215
213
}
216
214
217
-
218
215
@ Override
219
216
public String toString () {
220
217
StringBuilder sb = new StringBuilder ("ExponentialBackOff{" );
0 commit comments