Class RetryPolicySettings
java.lang.Object
org.springframework.boot.retry.RetryPolicySettings
Settings for a
RetryPolicy.- Since:
- 4.0.0
- Author:
- Stephane Nicoll
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreate aRetryPolicybased on the state of this instance.getDelay()Return the base delay after the initial invocation.Return the non-applicable exception types to avoid a retry for.Return the applicable exception types to attempt a retry for.Return the predicate to use to determine whether to retry a failed operation based on a givenThrowable.@Nullable DurationReturn the jitter period to enable random retry attempts.Return the maximum number of retry attempts.Return the maximum delay for any retry attempt.Return the value to multiply the current interval by for each attempt.voidSpecify the base delay after the initial invocation.voidsetExceptionExcludes(List<Class<? extends Throwable>> excludes) Replace the non-applicable exception types to attempt a retry for by the givenexcludes.voidsetExceptionIncludes(List<Class<? extends Throwable>> includes) Replace the applicable exception types to attempt a retry for by the givenincludes.voidsetExceptionPredicate(@Nullable Predicate<Throwable> exceptionPredicate) Set the predicate to use to determine whether to retry a failed operation based on a givenThrowable.voidsetFactory(@Nullable Function<RetryPolicy.Builder, RetryPolicy> factory) Set the factory to use to create theRetryPolicy, ornullto use the default.voidSpecify a jitter period for the base retry attempt, randomly subtracted or added to the calculated delay, resulting in a value betweendelay - jitteranddelay + jitterbut never below the base delay or above the max delay.voidsetMaxAttempts(Long maxAttempts) Specify the maximum number of retry attempts.voidsetMaxDelay(Duration maxDelay) Specify the maximum delay for any retry attempt, limiting how far jitter and the multiplier can increase the delay.voidsetMultiplier(Double multiplier) Specify a multiplier for a delay for the next retry attempt.
-
Field Details
-
DEFAULT_MAX_ATTEMPTS
public static final long DEFAULT_MAX_ATTEMPTSDefault number of retry attempts.- See Also:
-
DEFAULT_DELAY
Default initial delay. -
DEFAULT_MULTIPLIER
public static final double DEFAULT_MULTIPLIERDefault multiplier, uses a fixed delay.- See Also:
-
DEFAULT_MAX_DELAY
Default maximum delay (infinite).
-
-
Constructor Details
-
RetryPolicySettings
public RetryPolicySettings()
-
-
Method Details
-
createRetryPolicy
Create aRetryPolicybased on the state of this instance.- Returns:
- a
RetryPolicy
-
getExceptionIncludes
-
setExceptionIncludes
Replace the applicable exception types to attempt a retry for by the givenincludes. Alternatively consider usinggetExceptionIncludes()to mutate the existing list.- Parameters:
includes- the applicable exception types
-
getExceptionExcludes
-
setExceptionExcludes
Replace the non-applicable exception types to attempt a retry for by the givenexcludes. Alternatively consider usinggetExceptionExcludes()to mutate the existing list.- Parameters:
excludes- the non-applicable types
-
getExceptionPredicate
-
setExceptionPredicate
-
getMaxAttempts
Return the maximum number of retry attempts.- Returns:
- the maximum number of retry attempts
- See Also:
-
setMaxAttempts
Specify the maximum number of retry attempts.- Parameters:
maxAttempts- the max attempts (must be equal or greater than zero)
-
getDelay
Return the base delay after the initial invocation.- Returns:
- the base delay
- See Also:
-
setDelay
Specify the base delay after the initial invocation.If a multiplier is specified, this serves as the initial delay to multiply from.
- Parameters:
delay- the base delay (must be greater than or equal to zero)
-
getJitter
Return the jitter period to enable random retry attempts.- Returns:
- the jitter value
-
setJitter
Specify a jitter period for the base retry attempt, randomly subtracted or added to the calculated delay, resulting in a value betweendelay - jitteranddelay + jitterbut never below the base delay or above the max delay.If a multiplier is specified, it is applied to the jitter value as well.
- Parameters:
jitter- the jitter value (must be positive)
-
getMultiplier
Return the value to multiply the current interval by for each attempt. The default value,1.0, effectively results in a fixed delay.- Returns:
- the value to multiply the current interval by for each attempt
- See Also:
-
setMultiplier
Specify a multiplier for a delay for the next retry attempt.- Parameters:
multiplier- value to multiply the current interval by for each attempt (must be greater than or equal to 1)
-
getMaxDelay
Return the maximum delay for any retry attempt.- Returns:
- the maximum delay
-
setMaxDelay
Specify the maximum delay for any retry attempt, limiting how far jitter and the multiplier can increase the delay.The default is unlimited.
- Parameters:
maxDelay- the maximum delay (must be positive)- See Also:
-
setFactory
Set the factory to use to create theRetryPolicy, ornullto use the default. The function takes aRetryPolicy.Builderinitialized with the state of this instance that can be further configured, or ignored to restart from scratch.- Parameters:
factory- a factory to customize the retry policy.
-