/** * Retry the given operation with the given delay in between failures. * * @param operation to retry * @param retries number of retries * @param retryDelay delay between retries * @param retryPredicate Predicate to test whether an exception is retryable * @param scheduledExecutor executor to be used for the retry operation * @param <T> type of the result * @return Future which retries the given operation a given amount of times and delays the retry in case of failures */ public static <T> CompletableFuture<T> retryWithDelay( final Supplier<CompletableFuture<T>> operation, final int retries, final Time retryDelay, final Predicate<Throwable> retryPredicate, final ScheduledExecutor scheduledExecutor) { final CompletableFuture<T> resultFuture = new CompletableFuture<>(); retryOperationWithDelay( resultFuture, operation, retries, retryDelay, retryPredicate, scheduledExecutor); return resultFuture; }
/** * Retry the given operation with the given delay in between failures. * * @param operation to retry * @param retries number of retries * @param retryDelay delay between retries * @param retryPredicate Predicate to test whether an exception is retryable * @param scheduledExecutor executor to be used for the retry operation * @param <T> type of the result * @return Future which retries the given operation a given amount of times and delays the retry in case of failures */ public static <T> CompletableFuture<T> retryWithDelay( final Supplier<CompletableFuture<T>> operation, final int retries, final Time retryDelay, final Predicate<Throwable> retryPredicate, final ScheduledExecutor scheduledExecutor) { final CompletableFuture<T> resultFuture = new CompletableFuture<>(); retryOperationWithDelay( resultFuture, operation, retries, retryDelay, retryPredicate, scheduledExecutor); return resultFuture; }
/** * Retry the given operation with the given delay in between failures. * * @param operation to retry * @param retries number of retries * @param retryDelay delay between retries * @param retryPredicate Predicate to test whether an exception is retryable * @param scheduledExecutor executor to be used for the retry operation * @param <T> type of the result * @return Future which retries the given operation a given amount of times and delays the retry in case of failures */ public static <T> CompletableFuture<T> retryWithDelay( final Supplier<CompletableFuture<T>> operation, final int retries, final Time retryDelay, final Predicate<Throwable> retryPredicate, final ScheduledExecutor scheduledExecutor) { final CompletableFuture<T> resultFuture = new CompletableFuture<>(); retryOperationWithDelay( resultFuture, operation, retries, retryDelay, retryPredicate, scheduledExecutor); return resultFuture; }
if (retries > 0 && retryPredicate.test(throwable)) { final ScheduledFuture<?> scheduledFuture = scheduledExecutor.schedule( () -> retryOperationWithDelay(resultFuture, operation, retries - 1, retryDelay, retryPredicate, scheduledExecutor), retryDelay.toMilliseconds(), TimeUnit.MILLISECONDS);
} else if (retries > 0) { final ScheduledFuture<?> scheduledFuture = scheduledExecutor.schedule( (Runnable) () -> retryOperationWithDelay(resultFuture, operation, retries - 1, retryDelay, retryPredicate, scheduledExecutor), retryDelay.toMilliseconds(), TimeUnit.MILLISECONDS);
} else if (retries > 0) { final ScheduledFuture<?> scheduledFuture = scheduledExecutor.schedule( (Runnable) () -> retryOperationWithDelay(resultFuture, operation, retries - 1, retryDelay, retryPredicate, scheduledExecutor), retryDelay.toMilliseconds(), TimeUnit.MILLISECONDS);