Package io.github.resilience4j.retry
Class RetryConfig.Builder<T>
java.lang.Object
io.github.resilience4j.retry.RetryConfig.Builder<T>
- Enclosing class:
- RetryConfig
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()consumeResultBeforeRetryAttempt(BiConsumer<Integer, T> consumeResultBeforeRetryAttempt) Configure a BiConsumer which performs post actions if a result should be retried.failAfterMaxAttempts(boolean bool) Configures the Retry to throw aMaxRetriesExceededexception oncemaxAttemptshas been reached, and the result is still not satisfactory (according toretryOnResultPredicate)final RetryConfig.Builder<T>ignoreExceptions(Class<? extends Throwable>... errorClasses) Configures a list of error classes that are ignored and thus are not retried.intervalBiFunction(io.github.resilience4j.core.IntervalBiFunction<T> f) Set a function to modify the waiting interval after a failure based on attempt number and result or exception.intervalFunction(io.github.resilience4j.core.IntervalFunction f) Set a function to modify the waiting interval after a failure.maxAttempts(int maxAttempts) final RetryConfig.Builder<T>retryExceptions(Class<? extends Throwable>... errorClasses) Configures a list of error classes that are recorded as a failure and thus are retried.retryOnException(Predicate<Throwable> predicate) Configures a Predicate which evaluates if an exception should be retried.retryOnResult(Predicate<T> predicate) Configures a Predicate which evaluates if an result should be retried.toString()waitDuration(Duration waitDuration) writableStackTraceEnabled(boolean bool) Enables writable stack traces.
-
Constructor Details
-
Builder
public Builder() -
Builder
-
-
Method Details
-
toString
-
maxAttempts
-
waitDuration
-
retryOnResult
Configures a Predicate which evaluates if an result should be retried. The Predicate must return true if the result should be retried, otherwise it must return false.- Parameters:
predicate- the Predicate which evaluates if an result should be retried or not.- Returns:
- the RetryConfig.Builder
-
consumeResultBeforeRetryAttempt
public RetryConfig.Builder<T> consumeResultBeforeRetryAttempt(BiConsumer<Integer, T> consumeResultBeforeRetryAttempt) Configure a BiConsumer which performs post actions if a result should be retried.- Parameters:
consumeResultBeforeRetryAttempt- the BiConsumer which performs post actions if a result should be retried.- Returns:
- the RetryConfig.Builder
-
failAfterMaxAttempts
Configures the Retry to throw aMaxRetriesExceededexception oncemaxAttemptshas been reached, and the result is still not satisfactory (according toretryOnResultPredicate)- Parameters:
bool- a boolean flag to enable or disable throwing. (Default isfalse- Returns:
- the RetryConfig.Builder
-
writableStackTraceEnabled
Enables writable stack traces. When set to false,Throwable.getStackTrace()returns a zero length array. This may be used to reduce log spam when the Retry has exceeded the maximum nbr of attempts, and flagfailAfterMaxAttemptshas been enabled. The thrownMaxRetriesExceededExceptionwill then have no stacktrace.- Parameters:
bool- the flag to enable writable stack traces.- Returns:
- the RetryConfig.Builder
-
intervalFunction
Set a function to modify the waiting interval after a failure. By default the interval stays the same.- Parameters:
f- Function to modify the interval after a failure- Returns:
- the RetryConfig.Builder
-
intervalBiFunction
public RetryConfig.Builder<T> intervalBiFunction(io.github.resilience4j.core.IntervalBiFunction<T> f) Set a function to modify the waiting interval after a failure based on attempt number and result or exception.- Parameters:
f- Function to modify the interval after a failure- Returns:
- the RetryConfig.Builder
-
retryOnException
Configures a Predicate which evaluates if an exception should be retried. The Predicate must return true if the exception should be retried, otherwise it must return false.- Parameters:
predicate- the Predicate which evaluates if an exception should be retried or not.- Returns:
- the RetryConfig.Builder
-
retryExceptions
@SafeVarargs public final RetryConfig.Builder<T> retryExceptions(@Nullable Class<? extends Throwable>... errorClasses) Configures a list of error classes that are recorded as a failure and thus are retried. Any exception matching or inheriting from one of the list will be retried, unless ignored via- Parameters:
errorClasses- the error classes that are retried- Returns:
- the RetryConfig.Builder
- See Also:
-
ignoreExceptions
@SafeVarargs public final RetryConfig.Builder<T> ignoreExceptions(@Nullable Class<? extends Throwable>... errorClasses) Configures a list of error classes that are ignored and thus are not retried. Any exception matching or inheriting from one of the list will not be retried, even if marked via- Parameters:
errorClasses- the error classes that are retried- Returns:
- the RetryConfig.Builder
- See Also:
-
. Ignoring an exception has priority over retrying an exception.Example: ignoreExceptions(Throwable.class) and retryOnExceptions(Exception.class) would capture nothing
Example: ignoreExceptions(Exception.class) and retryOnExceptions(Throwable.class) would capture Errors
For a more sophisticated exception management use the
method
-
build
-