Class RetryPolicySettings

java.lang.Object
org.springframework.boot.retry.RetryPolicySettings

public final class RetryPolicySettings extends Object
Settings for a RetryPolicy.
Since:
4.0.0
Author:
Stephane Nicoll
  • Field Details

    • DEFAULT_MAX_ATTEMPTS

      public static final long DEFAULT_MAX_ATTEMPTS
      Default number of retry attempts.
      See Also:
    • DEFAULT_DELAY

      public static final Duration DEFAULT_DELAY
      Default initial delay.
    • DEFAULT_MULTIPLIER

      public static final double DEFAULT_MULTIPLIER
      Default multiplier, uses a fixed delay.
      See Also:
    • DEFAULT_MAX_DELAY

      public static final Duration DEFAULT_MAX_DELAY
      Default maximum delay (infinite).
  • Constructor Details

    • RetryPolicySettings

      public RetryPolicySettings()
  • Method Details

    • createRetryPolicy

      public RetryPolicy createRetryPolicy()
      Create a RetryPolicy based on the state of this instance.
      Returns:
      a RetryPolicy
    • getMaxAttempts

      public Long getMaxAttempts()
      Return the maximum number of retry attempts.
      Returns:
      the maximum number of retry attempts
      See Also:
    • setMaxAttempts

      public void setMaxAttempts(Long maxAttempts)
      Specify the maximum number of retry attempts.
      Parameters:
      maxAttempts - the max attempts (must be equal or greater than zero)
    • getDelay

      public Duration getDelay()
      Return the base delay after the initial invocation.
      Returns:
      the base delay
      See Also:
    • setDelay

      public void setDelay(Duration delay)
      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

      public @Nullable Duration getJitter()
      Return the jitter period to enable random retry attempts.
      Returns:
      the jitter value
    • setJitter

      public void setJitter(@Nullable Duration jitter)
      Specify a jitter period for the base retry attempt, randomly subtracted or added to the calculated delay, resulting in a value between delay - jitter and delay + jitter but 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

      public Double 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

      public void setMultiplier(Double multiplier)
      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

      public Duration getMaxDelay()
      Return the maximum delay for any retry attempt.
      Returns:
      the maximum delay
    • setMaxDelay

      public void setMaxDelay(Duration maxDelay)
      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

      public void setFactory(@Nullable Function<RetryPolicy.Builder, RetryPolicy> factory)
      Set the factory to use to create the RetryPolicy, or null to use the default. The function takes a RetryPolicy.Builder initialized 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.