Interface RetryPolicy


public interface RetryPolicy
Strategy interface to define a retry policy.

Also provides factory methods and a fluent builder API for creating retry policies with common configurations. See withDefaults(), withMaxRetries(long), builder(), and the configuration options in RetryPolicy.Builder for details.

Since:
7.0
Author:
Sam Brannen, Mahmoud Ben Hassine
See Also:
  • Method Details

    • shouldRetry

      boolean shouldRetry(Throwable throwable)
      Specify if the Retryable operation should be retried based on the given throwable.
      Parameters:
      throwable - the exception that caused the operation to fail
      Returns:
      true if the operation should be retried, false otherwise
    • getTimeout

      default Duration getTimeout()
      Get the timeout to use for this retry policy.

      The returned Duration represents the maximum amount of elapsed time allowed for the initial invocation and any subsequent retry attempts, including delays.

      Defaults to Duration.ZERO which signals that no timeout should be applied.

      Returns:
      the timeout to apply
      Since:
      7.0.2
      See Also:
    • getBackOff

      default BackOff getBackOff()
      Get the BackOff strategy to use for this retry policy.

      Defaults to a fixed backoff of 1000L milliseconds and maximum 3L retries.

      Note that total attempts = 1 initial attempt + maxRetries attempts. Thus, when maxRetries is set to 3, a retryable operation will be invoked at least once and at most 4 times.

      Returns:
      the BackOff strategy to use
      See Also:
    • withDefaults

      static RetryPolicy withDefaults()
      Create a RetryPolicy with default configuration.

      The returned policy applies to all exception types, uses a fixed backoff of 1000L milliseconds, and supports maximum 3L retries.

      Note that total attempts = 1 initial attempt + maxRetries attempts. Thus, when maxRetries is set to 3, a retryable operation will be invoked at least once and at most 4 times.

      See Also:
    • withMaxRetries

      static RetryPolicy withMaxRetries(long maxRetries)
      Create a RetryPolicy configured with a maximum number of retry attempts.

      Note that total attempts = 1 initial attempt + maxRetries attempts. Thus, if maxRetries is set to 4, a retryable operation will be invoked at least once and at most 5 times.

      The returned policy applies to all exception types and uses a fixed backoff of 1000L milliseconds.

      Parameters:
      maxRetries - the maximum number of retry attempts; must be positive (or zero for no retry)
      See Also:
    • builder

      static RetryPolicy.Builder builder()
      Create a RetryPolicy.Builder to configure a RetryPolicy with common configuration options.