Class Retryable<X>
java.lang.Object
com.broadleafcommerce.dataexchange.domain.util.Retryable<X>
- Type Parameters:
X
-
Implementation of
Callable
, Runnable
, and Supplier
interfaces that wraps
another delegate Callable
in retry logic. This is often used to schedule an asynchronous
task. For example, Executor.execute(Runnable)
or
AsyncTaskExecutor.submit(Callable)
or
CompletableFuture.supplyAsync(Supplier, Executor)
.
However, this can just as easily be used synchronously to ensure that retry semantics are applied
to a given execution.- Author:
- Kelly Tisdell (ktisdell)
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <X> Retryable.RetryableBuilder<X>
builder()
call()
Executes theCallable
delegate in the context of retry semantics.defaultRetryPredicate
(Predicate<Throwable> retryPredicate) Takes the providedPredicate
and adds default logic.get()
Executes theCallable
delegate in the context of retry semantics.void
run()
Executes theCallable
delegate in the context of retry semantics.
-
Constructor Details
-
Retryable
-
-
Method Details
-
defaultRetryPredicate
@NonNull public static Predicate<Throwable> defaultRetryPredicate(@Nullable Predicate<Throwable> retryPredicate) Takes the providedPredicate
and adds default logic. By default, the followingthrowables
will not be retried:Error
NullPointerException
IllegalArgumentException
InterruptedException
InterruptedIOException
TimeoutException
CancellationException
WebClientResponseException
will not be retried, except for the following:WebClientResponseException.InternalServerError
WebClientResponseException.ServiceUnavailable
WebClientResponseException.BadGateway
WebClientResponseException.GatewayTimeout
WebClientResponseException.TooManyRequests
WebClientResponseException.Conflict
Predicate
is null it will be treated as returning true by default. -
builder
-
call
Executes theCallable
delegate in the context of retry semantics. This method will throw any exceptions after the retry logic has been tried and the exceptionexceptionConsumer
has received the exception. Note that theexceptionConsumer
may re-throw the exception as aRuntimeException
. This is exactly the same as theget()
method except that it will throw an exception if an exception is caught after retry logic. TheexceptionConsumer
might also throw aRuntimeException
, in which case that will be the exception thrown out of this method.- Specified by:
call
in interfaceCallable<X>
- Returns:
- the result of
Callable.call()
with retry semantics in case of an error - Throws:
Exception
- if an exception is thrown
-
get
Executes theCallable
delegate in the context of retry semantics. This method will not normally throw any exceptions after the retry logic has been tried and the exceptionexceptionConsumer
has received the exception. This is exactly the same as thecall()
method except that it will NOT normally throw an exception. Rather if an exception is encountered after retries, then this will call theexceptionConsumer
and returnnull
. Note that theexceptionConsumer
may re-throw the exception as aRuntimeException
. So, while this method will catch the exception and pass it to theexceptionConsumer
, it will not, by default, throw that exception. But theexceptionConsumer
might, depending on its implementation.- Specified by:
get
in interfaceSupplier<X>
- Returns:
- the result of the delegate
Callable.call()
with retry semantics in case of an error
-
run
public void run()Executes theCallable
delegate in the context of retry semantics. This method will not throw any exceptions after the retry logic has been tried and the exceptionexceptionConsumer
has received the exception. This is exactly the same as thecall()
andget()
methods except that it will NOT return a value and will NOT throw an exception. Rather if an exception is encountered after retries, then this will call theexceptionConsumer
and complete normally. Note that theexceptionConsumer
may re-throw the exception as aRuntimeException
. So, while this method will catch the exception and pass it to theexceptionConsumer
, it will not, by default, throw that exception. But theexceptionConsumer
might, depending on its implementation.
-