Class AsyncUtils
- java.lang.Object
-
- io.fabric8.kubernetes.client.utils.AsyncUtils
-
public class AsyncUtils extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
AsyncUtils.ShouldRetry<T>
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> CompletableFuture<T>
retryWithExponentialBackoff(Supplier<CompletableFuture<T>> action, Consumer<T> onCancel, Duration timeout, ExponentialBackoffIntervalCalculator retryIntervalCalculator, AsyncUtils.ShouldRetry<T> shouldRetry)
Returns a newCompletableFuture
that will complete once the action provided by the action supplier completes.static <T> CompletableFuture<T>
withTimeout(CompletableFuture<T> future, Duration timeout)
Returns the providedCompletableFuture
that will complete exceptionally with aTimeoutException
if the providedDuration
timeout period is exceeded.
-
-
-
Method Detail
-
withTimeout
public static <T> CompletableFuture<T> withTimeout(CompletableFuture<T> future, Duration timeout)
Returns the providedCompletableFuture
that will complete exceptionally with aTimeoutException
if the providedDuration
timeout period is exceeded.- Type Parameters:
T
- the result type returned by the future.- Parameters:
future
- the future to add a timeout to.timeout
- the timeout duration.- Returns:
- the provided future with a timeout.
-
retryWithExponentialBackoff
public static <T> CompletableFuture<T> retryWithExponentialBackoff(Supplier<CompletableFuture<T>> action, Consumer<T> onCancel, Duration timeout, ExponentialBackoffIntervalCalculator retryIntervalCalculator, AsyncUtils.ShouldRetry<T> shouldRetry)
Returns a newCompletableFuture
that will complete once the action provided by the action supplier completes. The action will be retried with an exponential backoff using theExponentialBackoffIntervalCalculator
as long as theAsyncUtils.ShouldRetry
predicate returns a non-negative value. Each action retrieval retry will time out after the provided timeoutDuration
.- Type Parameters:
T
- the result type returned by the future.- Parameters:
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.- Returns:
- a new
CompletableFuture
that will complete once the action provided by the action supplier completes.
-
-