Class RetryPolicySettings
java.lang.Object
org.springframework.boot.retry.RetryPolicySettings
Settings for a
RetryPolicy.- Since:
- 4.0.0
- Author:
- Stephane Nicoll
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationDefault initial delay.static final DurationDefault maximum delay (infinite).static final longDefault number of retry attempts.static final doubleDefault multiplier, uses a fixed delay.static final DurationDefault maximum elapsed time (infinite). -
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 delay for any retry attempt.Return the maximum number of retry attempts.Return the value to multiply the current interval by for each attempt.Return the timeout for the maximum amount of elapsed time allowed for the initial invocation and any subsequent retry attempts, including delays.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.voidsetMaxDelay(Duration maxDelay) Specify the maximum delay for any retry attempt, limiting how far jitter and the multiplier can increase the delay.voidsetMaxRetries(Long maxRetries) Specify the maximum number of retry attempts.voidsetMultiplier(Double multiplier) Specify a multiplier for a delay for the next retry attempt.voidsetTimeout(Duration timeout) Specify a timeout for the maximum amount of elapsed time allowed for the initial invocation and any subsequent retry attempts, including delays.
-
Field Details
-
DEFAULT_MAX_RETRIES
public static final long DEFAULT_MAX_RETRIESDefault number of retry attempts.- See Also:
-
DEFAULT_TIMEOUT
-
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
-
getMaxRetries
Return the maximum number of retry attempts.- Returns:
- the maximum number of retry attempts
- See Also:
-
setMaxRetries
Specify the maximum number of retry attempts.- Parameters:
maxRetries- the maximum number of retry attempts (must be equal or greater than zero)
-
getTimeout
Return the timeout for the maximum amount of elapsed time allowed for the initial invocation and any subsequent retry attempts, including delays.- Returns:
- the maximum duration the request can take
- Since:
- 4.2.0
-
setTimeout
Specify a timeout for the maximum amount of elapsed time allowed for the initial invocation and any subsequent retry attempts, including delays.The default is
Duration.ZERO, which signals that no timeout should be applied.- Parameters:
timeout- the timeout, typically in milliseconds or seconds; must be greater than or equal to zero- Since:
- 4.2.0
- See Also:
-
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.
-