in src/main/java/com/uber/uberscriptquery/util/ExponentialBackoffRetryPolicy.java [44:77]
public T attempt(Callable<T> callable) {
ThreadLocalRandom random = ThreadLocalRandom.current();
int remainingAttempts = maximumAttemptCount - 1;
long minimumSleepTime = minimumMilliseconds;
long maximumSleepTime = (long) (minimumSleepTime * retryScaleFactor);
Throwable previousException;
try {
return callable.call();
} catch (Throwable ex) {
if (remainingAttempts <= 0) {
throw new RuntimeException("Failed on first try and there is no remaining retry", ex);
}
previousException = ex;
}
while (remainingAttempts > 0) {
long sleepTime = random.nextLong(minimumSleepTime, maximumSleepTime);
LOG.info(String.format("Sleeping %s milliseconds and retrying on exception: %s", sleepTime, previousException));
Uninterruptibles.sleepUninterruptibly(sleepTime, TimeUnit.MILLISECONDS);
try {
return callable.call();
} catch (Throwable ex) {
previousException = ex;
}
remainingAttempts--;
minimumSleepTime *= retryScaleFactor;
maximumSleepTime *= retryScaleFactor;
}
String msg = String.format("Failed after tried %s times", maximumAttemptCount);
throw new RuntimeException(msg, previousException);
}