Class Retryable.RetryableBuilder<X>
java.lang.Object
com.broadleafcommerce.dataexchange.domain.util.Retryable.RetryableBuilder<X>
- Type Parameters:
X
-
Builder to assist in building a
Retryable
.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Returns am instance ofRetryable
based on thisRetryable.RetryableBuilder
.Convenient build method to return this instance as aCallable
.Convenient build method to return this instance as aRunnable
.Convenient build method to return this instance as aSupplier
.withCallable
(Callable<X> callable) Implementation of aCallable
functional interface or lambda.Use aRetryTemplate
that will execute no more than 3 tries (2 retries), using theRetryable.defaultRetryPredicate(Predicate)
and a conservative back-off policy that will not exceed 50 ms.withExceptionConsumer
(ExchangeObject exchangeObject, BatchContext<?> batchContext) Creates aConsumer
that callsBatchContext.registerException(String, Throwable)
using theExchangeObject.getCorrelationId()
as the key and logs the exception.Creates a defaultConsumer
implementation that simply throws aRuntimeException
with the provided exception as the cause.withRetryTemplate
(org.springframework.retry.support.RetryTemplate rt) Use the providedRetryTemplate
for retry semantics.withRunnable
(Runnable runnable) withSupplier
(Supplier<X> supplier)
-
Constructor Details
-
RetryableBuilder
public RetryableBuilder()
-
-
Method Details
-
withCallable
Implementation of aCallable
functional interface or lambda. This should be a rather short-lived or discrete, idempotent unit of work, since the whole point of this is to retry the execution of this callable in the event that errors are encountered.- Parameters:
callable
- the short, discrete, idempotent function to execute- Returns:
- the result of the execution of the provided
Callable
-
withSupplier
-
withRunnable
-
withDefaultRetryTemplate
Use aRetryTemplate
that will execute no more than 3 tries (2 retries), using theRetryable.defaultRetryPredicate(Predicate)
and a conservative back-off policy that will not exceed 50 ms.- Returns:
- this
Retryable.RetryableBuilder
for fluent chaining
-
withRetryTemplate
public Retryable.RetryableBuilder<X> withRetryTemplate(@NonNull org.springframework.retry.support.RetryTemplate rt) Use the providedRetryTemplate
for retry semantics.- Parameters:
rt
- the providedRetryTemplate
- Returns:
- this
Retryable.RetryableBuilder
for fluent chaining
-
withRethrowingExceptionConsumer
Creates a defaultConsumer
implementation that simply throws aRuntimeException
with the provided exception as the cause.- Returns:
- this
Retryable.RetryableBuilder
for fluent chaining
-
withExceptionConsumer
public Retryable.RetryableBuilder<X> withExceptionConsumer(ExchangeObject exchangeObject, BatchContext<?> batchContext) Creates aConsumer
that callsBatchContext.registerException(String, Throwable)
using theExchangeObject.getCorrelationId()
as the key and logs the exception.- Parameters:
exchangeObject
- used to provide the key to the MapbatchContext
- the container that holds Exceptions for eachExchangeObject
- Returns:
- this
Retryable.RetryableBuilder
for fluent chaining
-
build
Returns am instance ofRetryable
based on thisRetryable.RetryableBuilder
.Retryable
implementsCallable
,Supplier
, andRunnable
, and executes each of them similarly, except for thereturn
semantics and/or thethrows
semantics. If noRetryTemplate
is provided, then a default will be used. If not exceptionConsumer
is provided, a default logging consumer will be used. TheCallable
delegate is required to be provided.- Returns:
- Retryable instance
- See Also:
-
buildSupplier
-
buildRunnable
-
buildCallable
-