Class Retries
java.lang.Object
org.apache.bookkeeper.common.util.Retries
A util class for supporting retries with customized backoff.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic <ReturnT> CompletableFuture<ReturnT>run(Stream<Long> backoffs, Predicate<Throwable> retryPredicate, Supplier<CompletableFuture<ReturnT>> task, OrderedScheduler scheduler) Retry a giventaskon failures.static <ReturnT> CompletableFuture<ReturnT>run(Stream<Long> backoffs, Predicate<Throwable> retryPredicate, Supplier<CompletableFuture<ReturnT>> task, OrderedScheduler scheduler, Object key) Retry a giventaskon failures.
-
Field Details
-
NonFatalPredicate
-
-
Method Details
-
run
public static <ReturnT> CompletableFuture<ReturnT> run(Stream<Long> backoffs, Predicate<Throwable> retryPredicate, Supplier<CompletableFuture<ReturnT>> task, OrderedScheduler scheduler) Retry a giventaskon failures.It is a shortcut of
run(Stream, Predicate, Supplier, OrderedScheduler, Object)that runs retries on any threads in the providedscheduler.- Type Parameters:
ReturnT- the return type- Parameters:
backoffs- a stream of backoff delays, in milliseconds.retryPredicate- a predicate to test if failures are retryable.task- a task to execute.scheduler- scheduler to schedule the task and complete the futures.- Returns:
- future represents the result of the task with retries.
-
run
public static <ReturnT> CompletableFuture<ReturnT> run(Stream<Long> backoffs, Predicate<Throwable> retryPredicate, Supplier<CompletableFuture<ReturnT>> task, OrderedScheduler scheduler, Object key) Retry a giventaskon failures.It will only retry the tasks when the predicate
retryPredicatetests it as a retryable failure and it doesn't exhaust the retry budget. The retry delays are defined in a stream of delay values (in milliseconds).If a schedule
keyis provided, thetaskwill be submitted to the scheduler using the provided schedulekeyand also the returned future will be completed in the same thread. Otherwise, the task and the returned future will be executed and scheduled on any threads in the scheduler.- Type Parameters:
ReturnT- the return type.- Parameters:
backoffs- a stream of backoff delays, in milliseconds.retryPredicate- a predicate to test if failures are retryable.task- a task to execute.scheduler- scheduler to schedule the task and complete the futures.key- the submit key for the scheduler.- Returns:
- future represents the result of the task with retries.
-