public class AsyncUtils extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
AsyncUtils.ShouldRetry<T> |
Modifier and Type | Method and Description |
---|---|
static <T> CompletableFuture<T> |
retryWithExponentialBackoff(Supplier<CompletableFuture<T>> action,
Consumer<T> onCancel,
Duration timeout,
ExponentialBackoffIntervalCalculator retryIntervalCalculator,
AsyncUtils.ShouldRetry<T> shouldRetry)
Returns a new
CompletableFuture that will complete once the action provided by the action supplier completes. |
static <T> CompletableFuture<T> |
withTimeout(CompletableFuture<T> future,
Duration timeout)
Returns the provided
CompletableFuture that will complete exceptionally with a TimeoutException
if the provided Duration timeout period is exceeded. |
public static <T> CompletableFuture<T> withTimeout(CompletableFuture<T> future, Duration timeout)
CompletableFuture
that will complete exceptionally with a TimeoutException
if the provided Duration
timeout period is exceeded.T
- the result type returned by the future.future
- the future to add a timeout to.timeout
- the timeout duration.public static <T> CompletableFuture<T> retryWithExponentialBackoff(Supplier<CompletableFuture<T>> action, Consumer<T> onCancel, Duration timeout, ExponentialBackoffIntervalCalculator retryIntervalCalculator, AsyncUtils.ShouldRetry<T> shouldRetry)
CompletableFuture
that will complete once the action provided by the action supplier completes.
The action will be retried with an exponential backoff using the ExponentialBackoffIntervalCalculator
as
long as the AsyncUtils.ShouldRetry
predicate returns true.
Each action retrieval retry will time out after the provided timeout Duration
.T
- the result type returned by the future.action
- the action supplier.onCancel
- consumes the intermediate result in case the returned future is cancelled or each time the action is
retried.timeout
- the timeout duration.retryIntervalCalculator
- the retry interval calculator.shouldRetry
- the predicate to compute if the action is to be retried.CompletableFuture
that will complete once the action provided by the action supplier completes.Copyright © 2015–2024 Red Hat. All rights reserved.