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(), withMaxAttempts(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
    • 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 retry attempts.

      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 retry attempts.

      See Also:
    • withMaxAttempts

      static RetryPolicy withMaxAttempts(long maxAttempts)
      Create a RetryPolicy configured with a maximum number of retry attempts.

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

      Parameters:
      maxAttempts - 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.