Interface RetryListener
- All Known Implementing Classes:
CompositeRetryListener
public interface RetryListener
RetryListener defines a listener API for reacting to events
published during the execution of a Retryable operation.
Typically registered in a RetryTemplate, and can be composed using a
CompositeRetryListener.
- Since:
- 7.0
- Author:
- Mahmoud Ben Hassine, Sam Brannen, Juergen Hoeller
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidbeforeRetry(RetryPolicy retryPolicy, Retryable<?> retryable) Called before every retry attempt.default voidbeforeRetry(RetryPolicy retryPolicy, Retryable<?> retryable, RetryState retryState) Called before every retry attempt.default voidonRetryableExecution(RetryPolicy retryPolicy, Retryable<?> retryable, RetryState retryState) Called after every attempt, including the initial invocation.default voidonRetryFailure(RetryPolicy retryPolicy, Retryable<?> retryable, Throwable throwable) Called after every failed retry attempt.default voidonRetryPolicyExhaustion(RetryPolicy retryPolicy, Retryable<?> retryable, RetryException exception) Called if theRetryPolicyis exhausted.default voidonRetryPolicyInterruption(RetryPolicy retryPolicy, Retryable<?> retryable, RetryException exception) Called if theRetryPolicyis interrupted between retry attempts.default voidonRetryPolicyTimeout(RetryPolicy retryPolicy, Retryable<?> retryable, RetryException exception) Called if the configured timeout for aRetryPolicyis exceeded.default voidonRetrySuccess(RetryPolicy retryPolicy, Retryable<?> retryable, @Nullable Object result) Called after the first successful retry attempt.
-
Method Details
-
onRetryableExecution
default void onRetryableExecution(RetryPolicy retryPolicy, Retryable<?> retryable, RetryState retryState) Called after every attempt, including the initial invocation.The success of the attempt can be checked via
RetryState.isSuccessful(); if not successful, the current exception can be introspected viaRetryState.getLastException().- Parameters:
retryPolicy- theRetryPolicyretryable- theRetryableoperationretryState- the current state of retry processing (this is a live instance reflecting the current state; not intended to be stored)- Since:
- 7.0.2
- See Also:
-
beforeRetry
Called before every retry attempt.For a corresponding callback after every retry attempt, consider
onRetryableExecution(RetryPolicy, Retryable, RetryState), ignoring the initial attempt through a correspondingRetryState.getRetryCount()check.- Parameters:
retryPolicy- theRetryPolicyretryable- theRetryableoperationretryState- the current state of retry processing (this is a live instance reflecting the current state; not intended to be stored)- Since:
- 7.0.4
- See Also:
-
beforeRetry
Called before every retry attempt.Called by
beforeRetry(RetryPolicy, Retryable, RetryState). Implement either this reduced method or that full-argument method, not both.- Parameters:
retryPolicy- theRetryPolicyretryable- theRetryableoperation- See Also:
-
onRetrySuccess
default void onRetrySuccess(RetryPolicy retryPolicy, Retryable<?> retryable, @Nullable Object result) Called after the first successful retry attempt.- Parameters:
retryPolicy- theRetryPolicyretryable- theRetryableoperationresult- the result of theRetryableoperation
-
onRetryFailure
Called after every failed retry attempt.- Parameters:
retryPolicy- theRetryPolicyretryable- theRetryableoperationthrowable- the exception thrown by theRetryableoperation
-
onRetryPolicyExhaustion
default void onRetryPolicyExhaustion(RetryPolicy retryPolicy, Retryable<?> retryable, RetryException exception) Called if theRetryPolicyis exhausted.- Parameters:
retryPolicy- theRetryPolicyretryable- theRetryableoperationexception- the resultingRetryException, with the last exception thrown by theRetryableoperation as the cause and any exceptions from previous attempts as suppressed exceptions- See Also:
-
onRetryPolicyInterruption
default void onRetryPolicyInterruption(RetryPolicy retryPolicy, Retryable<?> retryable, RetryException exception) Called if theRetryPolicyis interrupted between retry attempts.- Parameters:
retryPolicy- theRetryPolicyretryable- theRetryableoperationexception- the resultingRetryException, with the last exception thrown by theRetryableoperation as the cause and any exceptions from previous attempts as suppressed exceptions- See Also:
-
onRetryPolicyTimeout
default void onRetryPolicyTimeout(RetryPolicy retryPolicy, Retryable<?> retryable, RetryException exception) Called if the configured timeout for aRetryPolicyis exceeded.- Parameters:
retryPolicy- theRetryPolicyretryable- theRetryableoperationexception- the resultingRetryException, with the last exception thrown by theRetryableoperation as the cause and any exceptions from previous attempts as suppressed exceptions- Since:
- 7.0.2
- See Also:
-