Interface RetryListener

All Known Implementing Classes:
MethodInvocationRetryListenerSupport, RetryListenerSupport, StatisticsListener

public interface RetryListener
Interface for listener that can be used to add behaviour to a retry. Implementations of RetryOperations can chose to issue callbacks to an interceptor during the retry lifecycle.
Author:
Dave Syer, Gary Russell, Henning Pƶttker
  • Method Details

    • open

      default <T, E extends Throwable> boolean open(RetryContext context, RetryCallback<T,E> callback)
      Called before the first attempt in a retry. For instance, implementers can set up state that is needed by the policies in the RetryOperations. The whole retry can be vetoed by returning false from this method, in which case a TerminatedRetryException will be thrown.
      Type Parameters:
      T - the type of object returned by the callback
      E - the type of exception it declares may be thrown
      Parameters:
      context - the current RetryContext.
      callback - the current RetryCallback.
      Returns:
      true if the retry should proceed.
    • close

      default <T, E extends Throwable> void close(RetryContext context, RetryCallback<T,E> callback, Throwable throwable)
      Called after the final attempt (successful or not). Allow the listener to clean up any resource it is holding before control returns to the retry caller.
      Type Parameters:
      E - the exception type
      T - the return value
      Parameters:
      context - the current RetryContext.
      callback - the current RetryCallback.
      throwable - the last exception that was thrown by the callback.
    • onSuccess

      default <T, E extends Throwable> void onSuccess(RetryContext context, RetryCallback<T,E> callback, T result)
      Called after a successful attempt; allow the listener to throw a new exception to cause a retry (according to the retry policy), based on the result returned by the RetryCallback.doWithRetry(RetryContext)
      Type Parameters:
      T - the return type.
      Parameters:
      context - the current RetryContext.
      callback - the current RetryCallback.
      result - the result returned by the callback method.
      Since:
      2.0
    • onError

      default <T, E extends Throwable> void onError(RetryContext context, RetryCallback<T,E> callback, Throwable throwable)
      Called after every unsuccessful attempt at a retry.
      Type Parameters:
      T - the return value
      E - the exception to throw
      Parameters:
      context - the current RetryContext.
      callback - the current RetryCallback.
      throwable - the last exception that was thrown by the callback.