/** * Retry the given operation with the given delay in between successful completions where the * result does not match a given predicate. * * @param operation to retry * @param retryDelay delay between retries * @param deadline A deadline that specifies at what point we should stop retrying * @param acceptancePredicate Predicate to test whether the result is acceptable * @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 the predicate isn't matched */ public static <T> CompletableFuture<T> retrySuccessfulWithDelay( final Supplier<CompletableFuture<T>> operation, final Time retryDelay, final Deadline deadline, final Predicate<T> acceptancePredicate, final ScheduledExecutor scheduledExecutor) { final CompletableFuture<T> resultFuture = new CompletableFuture<>(); retrySuccessfulOperationWithDelay( resultFuture, operation, retryDelay, deadline, acceptancePredicate, scheduledExecutor); return resultFuture; }
/** * Retry the given operation with the given delay in between successful completions where the * result does not match a given predicate. * * @param operation to retry * @param retryDelay delay between retries * @param deadline A deadline that specifies at what point we should stop retrying * @param acceptancePredicate Predicate to test whether the result is acceptable * @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 the predicate isn't matched */ public static <T> CompletableFuture<T> retrySuccessfulWithDelay( final Supplier<CompletableFuture<T>> operation, final Time retryDelay, final Deadline deadline, final Predicate<T> acceptancePredicate, final ScheduledExecutor scheduledExecutor) { final CompletableFuture<T> resultFuture = new CompletableFuture<>(); retrySuccessfulOperationWithDelay( resultFuture, operation, retryDelay, deadline, acceptancePredicate, scheduledExecutor); return resultFuture; }
/** * Retry the given operation with the given delay in between successful completions where the * result does not match a given predicate. * * @param operation to retry * @param retryDelay delay between retries * @param deadline A deadline that specifies at what point we should stop retrying * @param acceptancePredicate Predicate to test whether the result is acceptable * @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 the predicate isn't matched */ public static <T> CompletableFuture<T> retrySuccesfulWithDelay( final Supplier<CompletableFuture<T>> operation, final Time retryDelay, final Deadline deadline, final Predicate<T> acceptancePredicate, final ScheduledExecutor scheduledExecutor) { final CompletableFuture<T> resultFuture = new CompletableFuture<>(); retrySuccessfulOperationWithDelay( resultFuture, operation, retryDelay, deadline, acceptancePredicate, scheduledExecutor); return resultFuture; }
} else if (deadline.hasTimeLeft()) { final ScheduledFuture<?> scheduledFuture = scheduledExecutor.schedule( () -> retrySuccessfulOperationWithDelay(resultFuture, operation, retryDelay, deadline, acceptancePredicate, scheduledExecutor), retryDelay.toMilliseconds(), TimeUnit.MILLISECONDS);
} else if (deadline.hasTimeLeft()) { final ScheduledFuture<?> scheduledFuture = scheduledExecutor.schedule( (Runnable) () -> retrySuccessfulOperationWithDelay(resultFuture, operation, retryDelay, deadline, acceptancePredicate, scheduledExecutor), retryDelay.toMilliseconds(), TimeUnit.MILLISECONDS);
} else if (deadline.hasTimeLeft()) { final ScheduledFuture<?> scheduledFuture = scheduledExecutor.schedule( (Runnable) () -> retrySuccessfulOperationWithDelay(resultFuture, operation, retryDelay, deadline, acceptancePredicate, scheduledExecutor), retryDelay.toMilliseconds(), TimeUnit.MILLISECONDS);