Class Retries
- java.lang.Object
-
- org.apache.bookkeeper.common.util.Retries
-
public final class Retries extends java.lang.ObjectA util class for supporting retries with customized backoff.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.function.Predicate<java.lang.Throwable>NonFatalPredicate
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <ReturnT> java.util.concurrent.CompletableFuture<ReturnT>run(java.util.stream.Stream<java.lang.Long> backoffs, java.util.function.Predicate<java.lang.Throwable> retryPredicate, java.util.function.Supplier<java.util.concurrent.CompletableFuture<ReturnT>> task, OrderedScheduler scheduler)Retry a giventaskon failures.static <ReturnT> java.util.concurrent.CompletableFuture<ReturnT>run(java.util.stream.Stream<java.lang.Long> backoffs, java.util.function.Predicate<java.lang.Throwable> retryPredicate, java.util.function.Supplier<java.util.concurrent.CompletableFuture<ReturnT>> task, OrderedScheduler scheduler, java.lang.Object key)Retry a giventaskon failures.
-
-
-
Method Detail
-
run
public static <ReturnT> java.util.concurrent.CompletableFuture<ReturnT> run(java.util.stream.Stream<java.lang.Long> backoffs, java.util.function.Predicate<java.lang.Throwable> retryPredicate, java.util.function.Supplier<java.util.concurrent.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> java.util.concurrent.CompletableFuture<ReturnT> run(java.util.stream.Stream<java.lang.Long> backoffs, java.util.function.Predicate<java.lang.Throwable> retryPredicate, java.util.function.Supplier<java.util.concurrent.CompletableFuture<ReturnT>> task, OrderedScheduler scheduler, java.lang.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.
-
-