Interface RetryPolicy

All Superinterfaces:
Serializable
All Known Implementing Classes:
AlwaysRetryPolicy, BinaryExceptionClassifierRetryPolicy, CircuitBreakerRetryPolicy, CompositeRetryPolicy, ExceptionClassifierRetryPolicy, ExpressionRetryPolicy, MaxAttemptsRetryPolicy, NeverRetryPolicy, PredicateRetryPolicy, SimpleRetryPolicy, TimeoutRetryPolicy

public interface RetryPolicy extends Serializable
A RetryPolicy is responsible for allocating and managing resources needed by RetryOperations. The RetryPolicy allows retry operations to be aware of their context. Context can be internal to the retry framework, e.g. to support nested retries. Context can also be external, and the RetryPolicy provides a uniform API for a range of different platforms for the external context.
Author:
Dave Syer, Emanuele Ivaldi
  • Field Details

    • NO_MAXIMUM_ATTEMPTS_SET

      static final int NO_MAXIMUM_ATTEMPTS_SET
      The value returned by getMaxAttempts() when the policy doesn't provide a maximum number of attempts before failure
      See Also:
  • Method Details

    • canRetry

      boolean canRetry(RetryContext context)
      Parameters:
      context - the current retry status
      Returns:
      true if the operation can proceed
    • open

      RetryContext open(RetryContext parent)
      Acquire resources needed for the retry operation. The callback is passed in so that marker interfaces can be used and a manager can collaborate with the callback to set up some state in the status token.
      Parameters:
      parent - the parent context if we are in a nested retry.
      Returns:
      a RetryContext object specific to this policy.
    • close

      void close(RetryContext context)
      Parameters:
      context - a retry status created by the open(RetryContext) method of this policy.
    • registerThrowable

      void registerThrowable(RetryContext context, Throwable throwable)
      Called once per retry attempt, after the callback fails.
      Parameters:
      context - the current status object.
      throwable - the exception to throw
    • getMaxAttempts

      default int getMaxAttempts()
      Called to understand if the policy has a fixed number of maximum attempts before failure
      Returns:
      -1 if the policy doesn't provide a fixed number of maximum attempts before failure, the number of maximum attempts before failure otherwise