in src/main/java/com/uber/cadence/internal/common/RpcRetryer.java [232:268]
private static <R> ValueExceptionPair<R> failOrRetry(
RetryOptions options,
Supplier<CompletableFuture<R>> function,
int attempt,
long startTime,
AsyncBackoffThrottler throttler,
R r,
Throwable e) {
if (e == null) {
return new ValueExceptionPair<>(CompletableFuture.completedFuture(r), null);
}
if (e instanceof CompletionException) {
e = e.getCause();
}
// Do not retry Error
if (e instanceof Error) {
return new ValueExceptionPair<>(null, e);
}
e = unwrap((Exception) e);
long elapsed = System.currentTimeMillis() - startTime;
if (options.getDoNotRetry() != null) {
for (Class<?> exceptionToNotRetry : options.getDoNotRetry()) {
if (exceptionToNotRetry.isAssignableFrom(e.getClass())) {
return new ValueExceptionPair<>(null, e);
}
}
}
int maxAttempts = options.getMaximumAttempts();
if ((maxAttempts > 0 && attempt >= maxAttempts)
|| (options.getExpiration() != null && elapsed >= options.getExpiration().toMillis())) {
return new ValueExceptionPair<>(null, e);
}
log.debug("Retrying after failure", e);
CompletableFuture<R> next =
retryWithResultAsync(options, function, attempt + 1, startTime, throttler);
return new ValueExceptionPair<>(next, null);
}