RetryException
.
This executor calls user function and every time it throws RetryException
the call
repeats. It gives more control to the users on how to handle the retry and what actions to
perform between the retries. User can add application specific logging or even depending on
certain conditions decide not to retry anymore (not to throw RetryException
).
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<R> R
retry
(ThrowingSupplier<R, RetryException> supplier, Duration delay, int maxRetries) Calls supplier and returns its value.<R> R
retryIndefinitely
(ThrowingSupplier<R, RetryException> supplier, Duration delay) Calls supplier and returns its value.<R> CompletableFuture
<R> retryIndefinitelyAsync
(ThrowingSupplier<R, RetryException> supplier, Duration delay) Asynchronous version ofretryIndefinitely(ThrowingSupplier, Duration)
which returns aCompletableFuture
that completes only when supplier returns a value or future is cancelled.
-
Constructor Details
-
RetryableExecutor
public RetryableExecutor()
-
-
Method Details
-
retryIndefinitelyAsync
public <R> CompletableFuture<R> retryIndefinitelyAsync(ThrowingSupplier<R, RetryException> supplier, Duration delay) Asynchronous version ofretryIndefinitely(ThrowingSupplier, Duration)
which returns aCompletableFuture
that completes only when supplier returns a value or future is cancelled. -
retryIndefinitely
Calls supplier and returns its value.Every time supplier throws
RetryException
it is called again. It repeats indefinitely till supplier either returns a value or throwsRuntimeException
. -
retry
public <R> R retry(ThrowingSupplier<R, RetryException> supplier, Duration delay, int maxRetries) throws RetryExceptionCalls supplier and returns its value.Every time supplier throws
RetryException
it is retried again. When maxRetries limit is reached the retry stops andRetryException
is thrown to the caller withThrowable.getCause()
to be the original, last exception, which was thrown by the supplier.- Throws:
RetryException
-