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.Creates a defaultConsumerimplementation that simply does nothing when it consumes an exception.Creates a defaultConsumerimplementation that simply logs the exception as an error.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
-
withDefaultDoNothingExceptionConsumer
Creates a defaultConsumerimplementation that simply does nothing when it consumes an exception.- Returns:
- this
Retryable.RetryableBuilderfor fluent chaining
-
withDefaultErrorLoggingExceptionConsumer
Creates a defaultConsumerimplementation that simply logs the exception as an error.- 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
Consumerfunction that accepts anException. The purpose of this is to allow threads to register or track an exception when it occurs, without stopping a composite batch. The function may log, re-throw as aRuntimeException, or otherwise register or handle the Exception as desired.Consumersshould usually be careful not to throw exceptions since we often want to capture exceptions, but don't want to throw exceptions and otherwise stop composite processes. This does not, by default, log the exception. That is up to the implementor. Consider usingwithExceptionConsumer(ExchangeObject, BatchContext).- Parameters:
ec- an implementation of the exceptionConsumerfunction- 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
-