Interface RetryOperations

All Known Implementing Classes:
RetryTemplate

public interface RetryOperations
Interface specifying basic retry operations.

Implemented by RetryTemplate. Not often used directly, but a useful option to enhance testability, as it can easily be mocked or stubbed.

Inspired by the Spring Retry project but redesigned as a minimal core retry feature in the Spring Framework.

Since:
7.0
Author:
Mahmoud Ben Hassine, Juergen Hoeller
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    <R extends @Nullable Object>
    R
    execute(Retryable<R> retryable)
    Execute the given Retryable operation according to the RetryPolicy configured at the implementation level.
    void
    invoke(Runnable retryable)
    Invoke the given Runnable according to the RetryPolicy, returning successfully or throwing the last Runnable exception to the caller in case of retry policy exhaustion.
    <R extends @Nullable Object>
    R
    invoke(Supplier<R> retryable)
    Invoke the given Supplier according to the RetryPolicy, returning a successful result or throwing the last Supplier exception to the caller in case of retry policy exhaustion.
  • Method Details

    • execute

      <R extends @Nullable Object> R execute(Retryable<R> retryable) throws RetryException
      Execute the given Retryable operation according to the RetryPolicy configured at the implementation level.

      If the Retryable succeeds, its result will be returned. Otherwise, a RetryException will be thrown to the caller. The RetryException will contain the last exception thrown by the Retryable operation as the cause and any exceptions from previous attempts as suppressed exceptions.

      Type Parameters:
      R - the type of the result
      Parameters:
      retryable - the Retryable to execute and retry if needed
      Returns:
      the successful result of the Retryable, if any
      Throws:
      RetryException - if the RetryPolicy is exhausted. Note that this exception represents a failure outcome and is not meant to be propagated; you will typically rather rethrow its cause (the last original exception thrown by the Retryable callback) or throw a custom business exception instead.
    • invoke

      <R extends @Nullable Object> R invoke(Supplier<R> retryable)
      Invoke the given Supplier according to the RetryPolicy, returning a successful result or throwing the last Supplier exception to the caller in case of retry policy exhaustion.
      Type Parameters:
      R - the type of the result
      Parameters:
      retryable - the Supplier to invoke and retry if needed
      Returns:
      the result of the Supplier
      Throws:
      RuntimeException - if thrown by the Supplier
      Since:
      7.0.3
    • invoke

      void invoke(Runnable retryable)
      Invoke the given Runnable according to the RetryPolicy, returning successfully or throwing the last Runnable exception to the caller in case of retry policy exhaustion.
      Parameters:
      retryable - the Runnable to invoke and retry if needed
      Throws:
      RuntimeException - if thrown by the Runnable
      Since:
      7.0.3