@Test public void shouldBackoffTest() { assertFalse(Backoff.shouldBackoff(0L, TimeUnit.NANOSECONDS, 0)); long currentTimestamp = System.nanoTime(); assertTrue(Backoff.shouldBackoff(currentTimestamp, TimeUnit.NANOSECONDS, 100)); }
public static boolean shouldBackoff(long initialTimestamp, TimeUnit unitInitial, int failedAttempts, long defaultInterval, long maxBackoffInterval) { long initialTimestampInNano = unitInitial.toNanos(initialTimestamp); long currentTime = System.nanoTime(); long interval = defaultInterval; for (int i = 1; i < failedAttempts; i++) { interval = interval * 2; if (interval > maxBackoffInterval) { interval = maxBackoffInterval; break; } } return currentTime < (initialTimestampInNano + interval); }
Backoff { public static boolean shouldBackoff(long initialTimestamp, TimeUnit unitInitial, int failedAttempts, long defaultInterval, long maxBackoffInterval) { long initialTimestampInNano = unitInitial.toNanos(initialTimestamp); long currentTime = System.nanoTime(); long interval = defaultInterval; for (int i = 1; i < failedAttempts; i++) { interval = interval * 2; if (interval > maxBackoffInterval) { interval = maxBackoffInterval; break; } } return currentTime < (initialTimestampInNano + interval); } }
Backoff { public static boolean shouldBackoff(long initialTimestamp, TimeUnit unitInitial, int failedAttempts, long defaultInterval, long maxBackoffInterval) { long initialTimestampInNano = unitInitial.toNanos(initialTimestamp); long currentTime = System.nanoTime(); long interval = defaultInterval; for (int i = 1; i < failedAttempts; i++) { interval = interval * 2; if (interval > maxBackoffInterval) { interval = maxBackoffInterval; break; } } return currentTime < (initialTimestampInNano + interval); } @VisibleForTesting  Backoff(long initial, TimeUnit unitInitial, long max, TimeUnit unitMax, long mandatoryStop,
            TimeUnit unitMandatoryStop, Clock clock);  Backoff(long initial, TimeUnit unitInitial, long max, TimeUnit unitMax, long mandatoryStop,
                   TimeUnit unitMandatoryStop); }
Backoff { public static boolean shouldBackoff(long initialTimestamp, TimeUnit unitInitial, int failedAttempts, long defaultInterval, long maxBackoffInterval) { long initialTimestampInNano = unitInitial.toNanos(initialTimestamp); long currentTime = System.nanoTime(); long interval = defaultInterval; for (int i = 1; i < failedAttempts; i++) { interval = interval * 2; if (interval > maxBackoffInterval) { interval = maxBackoffInterval; break; } } return currentTime < (initialTimestampInNano + interval); } @VisibleForTesting  Backoff(long initial, TimeUnit unitInitial, long max, TimeUnit unitMax, long mandatoryStop,
            TimeUnit unitMandatoryStop, Clock clock);  Backoff(long initial, TimeUnit unitInitial, long max, TimeUnit unitMax, long mandatoryStop,
                   TimeUnit unitMandatoryStop); long next(); void reduceToHalf(); void reset(); static boolean shouldBackoff(long initialTimestamp, TimeUnit unitInitial, int failedAttempts,
    									long defaultInterval, long maxBackoffInterval); static boolean shouldBackoff(long initialTimestamp, TimeUnit unitInitial, int failedAttempts); }
Backoff { public static boolean shouldBackoff(long initialTimestamp, TimeUnit unitInitial, int failedAttempts, long defaultInterval, long maxBackoffInterval) { long initialTimestampInNano = unitInitial.toNanos(initialTimestamp); long currentTime = System.nanoTime(); long interval = defaultInterval; for (int i = 1; i < failedAttempts; i++) { interval = interval * 2; if (interval > maxBackoffInterval) { interval = maxBackoffInterval; break; } } return currentTime < (initialTimestampInNano + interval); } @VisibleForTesting  Backoff(long initial, TimeUnit unitInitial, long max, TimeUnit unitMax, long mandatoryStop,
            TimeUnit unitMandatoryStop, Clock clock);  Backoff(long initial, TimeUnit unitInitial, long max, TimeUnit unitMax, long mandatoryStop,
                   TimeUnit unitMandatoryStop); long next(); void reduceToHalf(); void reset(); static boolean shouldBackoff(long initialTimestamp, TimeUnit unitInitial, int failedAttempts,
    									long defaultInterval, long maxBackoffInterval); static boolean shouldBackoff(long initialTimestamp, TimeUnit unitInitial, int failedAttempts); static final long DEFAULT_INTERVAL_IN_NANOSECONDS; static final long MAX_BACKOFF_INTERVAL_NANOSECONDS; }