@@ -22,11 +22,20 @@ public int getAttemptsRemaining() {
2222 return this .attemptsRemaining ;
2323 }
2424
25+ /**
26+ * Waits for some random amount of time {@link BackoffCounter#calculateDelay()}
27+ * @throws InterruptedException
28+ */
2529 public void waitBackoff () throws InterruptedException {
2630 int delay = this .calculateDelay ();
2731 this .waitBackoff (delay );
2832 }
2933
34+ /**
35+ * Waits for specified amount of miliseconds.
36+ * @param delay Time to wait for in miliseconds.
37+ * @throws InterruptedException
38+ */
3039 public void waitBackoff (int delay ) throws InterruptedException {
3140 if (LOGGER .isWarnEnabled ()) {
3241 LOGGER .warn (String .format (
@@ -50,12 +59,16 @@ public void reset(int maxAttempts) {
5059 this .attemptsRemaining = maxAttempts ;
5160 }
5261
62+ /**
63+ * Generates some random amount of time to backoff.
64+ * Time is within <16000, 48000) ms
65+ * @return Time in miliseconds.
66+ */
5367 private int calculateDelay () {
5468 int exponent = this .maxAttempts - this .attemptsRemaining ;
5569 double minWindow = 1 - RANDOM_FACTOR ;
5670 double maxWindow = 1 + RANDOM_FACTOR ;
5771 double jitter = (Math .random () * (maxWindow - minWindow )) + minWindow ;
58-
5972 return (int ) (Math .pow (2 , exponent ) * BASE_TIMEOUT * jitter );
6073 }
6174}
0 commit comments