Package io.github.resilience4j.retry
Class RetryConfig.Builder<T>
- java.lang.Object
-
- io.github.resilience4j.retry.RetryConfig.Builder<T>
-
- Enclosing class:
- RetryConfig
public static class RetryConfig.Builder<T> extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description Builder()Builder(RetryConfig baseConfig)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RetryConfigbuild()RetryConfig.Builder<T>failAfterMaxAttempts(boolean bool)Configures the Retry to throw aMaxRetriesExceededexception oncemaxAttemptshas been reached, and the result is still not satisfactory (according toretryOnResultPredicate)RetryConfig.Builder<T>ignoreExceptions(java.lang.Class<? extends java.lang.Throwable>... errorClasses)Configures a list of error classes that are ignored and thus are not retried.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.RetryConfig.Builder<T>intervalFunction(io.github.resilience4j.core.IntervalFunction f)Set a function to modify the waiting interval after a failure.RetryConfig.Builder<T>maxAttempts(int maxAttempts)RetryConfig.Builder<T>retryExceptions(java.lang.Class<? extends java.lang.Throwable>... errorClasses)Configures a list of error classes that are recorded as a failure and thus are retried.RetryConfig.Builder<T>retryOnException(java.util.function.Predicate<java.lang.Throwable> predicate)Configures a Predicate which evaluates if an exception should be retried.RetryConfig.Builder<T>retryOnResult(java.util.function.Predicate<T> predicate)Configures a Predicate which evaluates if an result should be retried.RetryConfig.Builder<T>waitDuration(java.time.Duration waitDuration)RetryConfig.Builder<T>writableStackTraceEnabled(boolean bool)Enables writable stack traces.
-
-
-
Constructor Detail
-
Builder
public Builder()
-
Builder
public Builder(RetryConfig baseConfig)
-
-
Method Detail
-
maxAttempts
public RetryConfig.Builder<T> maxAttempts(int maxAttempts)
-
waitDuration
public RetryConfig.Builder<T> waitDuration(java.time.Duration waitDuration)
-
retryOnResult
public RetryConfig.Builder<T> retryOnResult(java.util.function.Predicate<T> predicate)
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
-
failAfterMaxAttempts
public RetryConfig.Builder<T> failAfterMaxAttempts(boolean bool)
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
public RetryConfig.Builder<T> writableStackTraceEnabled(boolean bool)
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
public RetryConfig.Builder<T> intervalFunction(io.github.resilience4j.core.IntervalFunction f)
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
public RetryConfig.Builder<T> retryOnException(java.util.function.Predicate<java.lang.Throwable> predicate)
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 java.lang.Class<? extends java.lang.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:
). Ignoring an exception has priority over retrying an exception. Example: retryOnExceptions(Throwable.class) and ignoreExceptions(RuntimeException.class) would retry all Errors and checked Exceptions, and ignore unchecked For a more sophisticated exception management use the,method
-
ignoreExceptions
@SafeVarargs public final RetryConfig.Builder<T> ignoreExceptions(@Nullable java.lang.Class<? extends java.lang.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
public RetryConfig build()
-
-