@Test public void testBackoffSleeper() throws InterruptedException { BackoffSleeper sleeper = new BackoffSleeper(50, 230, 2.0); long now = System.currentTimeMillis(); sleeper.sleep(); Assert.assertEquals(now + 50, System.currentTimeMillis(), 50); sleeper.sleep(); Assert.assertEquals(now + 150, System.currentTimeMillis(), 100); sleeper.sleep(); Assert.assertEquals(now + 350, System.currentTimeMillis(), 100); sleeper.sleep(); Assert.assertEquals(now + 580, System.currentTimeMillis(), 100); sleeper.sleep(); Assert.assertEquals(now + 810, System.currentTimeMillis(), 100); sleeper.reset(); Assert.assertEquals(now + 810, System.currentTimeMillis(), 100); sleeper.sleep(); Assert.assertEquals(now + 860, System.currentTimeMillis(), 100); }
public BackoffSleeper(long minWait, long maxWait, double backoffMultiplier) { if (minWait <= 0) { throw new IllegalArgumentException("Minimum wait must be at least 1 ms"); } if (maxWait <= minWait) { throw new IllegalArgumentException("Maximum wait must be greater than minimum wait"); } if (backoffMultiplier <= 1.0) { throw new IllegalArgumentException("Backoff multiplier must be greater than 1.0"); } _minWait = minWait; _maxWait = maxWait; _backoffMultiplier = backoffMultiplier; reset(); }
BackoffSleeper { public BackoffSleeper(long minWait, long maxWait, double backoffMultiplier) { if (minWait <= 0) { throw new IllegalArgumentException("Minimum wait must be at least 1 ms"); } if (maxWait <= minWait) { throw new IllegalArgumentException("Maximum wait must be greater than minimum wait"); } if (backoffMultiplier <= 1.0) { throw new IllegalArgumentException("Backoff multiplier must be greater than 1.0"); } _minWait = minWait; _maxWait = maxWait; _backoffMultiplier = backoffMultiplier; reset(); } }
BackoffSleeper { public BackoffSleeper(long minWait, long maxWait, double backoffMultiplier) { if (minWait <= 0) { throw new IllegalArgumentException("Minimum wait must be at least 1 ms"); } if (maxWait <= minWait) { throw new IllegalArgumentException("Maximum wait must be greater than minimum wait"); } if (backoffMultiplier <= 1.0) { throw new IllegalArgumentException("Backoff multiplier must be greater than 1.0"); } _minWait = minWait; _maxWait = maxWait; _backoffMultiplier = backoffMultiplier; reset(); } BackoffSleeper(long minWait, long maxWait, double backoffMultiplier); }
BackoffSleeper { public BackoffSleeper(long minWait, long maxWait, double backoffMultiplier) { if (minWait <= 0) { throw new IllegalArgumentException("Minimum wait must be at least 1 ms"); } if (maxWait <= minWait) { throw new IllegalArgumentException("Maximum wait must be greater than minimum wait"); } if (backoffMultiplier <= 1.0) { throw new IllegalArgumentException("Backoff multiplier must be greater than 1.0"); } _minWait = minWait; _maxWait = maxWait; _backoffMultiplier = backoffMultiplier; reset(); } BackoffSleeper(long minWait, long maxWait, double backoffMultiplier); void reset(); void sleep(); void stopSleeping(); }
BackoffSleeper { public BackoffSleeper(long minWait, long maxWait, double backoffMultiplier) { if (minWait <= 0) { throw new IllegalArgumentException("Minimum wait must be at least 1 ms"); } if (maxWait <= minWait) { throw new IllegalArgumentException("Maximum wait must be greater than minimum wait"); } if (backoffMultiplier <= 1.0) { throw new IllegalArgumentException("Backoff multiplier must be greater than 1.0"); } _minWait = minWait; _maxWait = maxWait; _backoffMultiplier = backoffMultiplier; reset(); } BackoffSleeper(long minWait, long maxWait, double backoffMultiplier); void reset(); void sleep(); void stopSleeping();  }