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 ofRetryablebased 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 aCallablefunctional interface or lambda.Use aRetryTemplatethat 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 aConsumerthat callsBatchContext.registerException(String, Throwable)using theExchangeObject.getCorrelationId()as the key and logs the exception.Creates a defaultConsumerimplementation that simply throws aRuntimeExceptionwith the provided exception as the cause.withRetryTemplate(org.springframework.retry.support.RetryTemplate rt) Use the providedRetryTemplatefor retry semantics.withRunnable(Runnable runnable) withSupplier(Supplier<X> supplier)
-
Constructor Details
-
RetryableBuilder
public RetryableBuilder()
-
-
Method Details
-
withCallable
Implementation of aCallablefunctional 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 aRetryTemplatethat 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.RetryableBuilderfor fluent chaining
-
withRetryTemplate
public Retryable.RetryableBuilder<X> withRetryTemplate(@NonNull org.springframework.retry.support.RetryTemplate rt) Use the providedRetryTemplatefor retry semantics.- Parameters:
rt- the providedRetryTemplate- Returns:
- this
Retryable.RetryableBuilderfor fluent chaining
-
withRethrowingExceptionConsumer
Creates a defaultConsumerimplementation that simply throws aRuntimeExceptionwith the provided exception as the cause.- Returns:
- this
Retryable.RetryableBuilderfor fluent chaining
-
withExceptionConsumer
public Retryable.RetryableBuilder<X> withExceptionConsumer(ExchangeObject exchangeObject, BatchContext<?> batchContext) Creates aConsumerthat 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.RetryableBuilderfor fluent chaining
-
build
Returns am instance ofRetryablebased on thisRetryable.RetryableBuilder.RetryableimplementsCallable,Supplier, andRunnable, and executes each of them similarly, except for thereturnsemantics and/or thethrowssemantics. If noRetryTemplateis provided, then a default will be used. If not exceptionConsumeris provided, a default logging consumer will be used. TheCallabledelegate is required to be provided.- Returns:
- Retryable instance
- See Also:
-
buildSupplier
-
buildRunnable
-
buildCallable
-