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_RETRIES

      public static final long DEFAULT_MAX_RETRIES
      Default number of retry attempts.
      See Also:
    • DEFAULT_TIMEOUT

      public static final Duration DEFAULT_TIMEOUT
      Default maximum elapsed time (infinite).
      Since:
      4.2.0
    • 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
    • getExceptionIncludes

      public List<Class<? extends Throwable>> getExceptionIncludes()
      Return the applicable exception types to attempt a retry for.

      The default is empty, leading to a retry attempt for any exception.

      Returns:
      the applicable exception types
    • setExceptionIncludes

      public void setExceptionIncludes(List<Class<? extends Throwable>> includes)
      Replace the applicable exception types to attempt a retry for by the given includes. Alternatively consider using getExceptionIncludes() to mutate the existing list.
      Parameters:
      includes - the applicable exception types
    • getExceptionExcludes

      public List<Class<? extends Throwable>> getExceptionExcludes()
      Return the non-applicable exception types to avoid a retry for.

      The default is empty, leading to a retry attempt for any exception.

      Returns:
      the non-applicable exception types
    • setExceptionExcludes

      public void setExceptionExcludes(List<Class<? extends Throwable>> excludes)
      Replace the non-applicable exception types to attempt a retry for by the given excludes. Alternatively consider using getExceptionExcludes() to mutate the existing list.
      Parameters:
      excludes - the non-applicable types
    • getExceptionPredicate

      public @Nullable Predicate<Throwable> getExceptionPredicate()
      Return the predicate to use to determine whether to retry a failed operation based on a given Throwable.
      Returns:
      the predicate to use
    • setExceptionPredicate

      public void setExceptionPredicate(@Nullable Predicate<Throwable> exceptionPredicate)
      Set the predicate to use to determine whether to retry a failed operation based on a given Throwable.
      Parameters:
      exceptionPredicate - the predicate to use
    • getMaxRetries

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

      public void setMaxRetries(Long maxRetries)
      Specify the maximum number of retry attempts.
      Parameters:
      maxRetries - the maximum number of retry attempts (must be equal or greater than zero)
    • getTimeout

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

      public void setTimeout(Duration timeout)
      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

      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.