Class CompositeRetryListener
java.lang.Object
org.springframework.core.retry.support.CompositeRetryListener
- All Implemented Interfaces:
RetryListener
A composite implementation of the
RetryListener interface, which is
used to compose multiple listeners within a
RetryTemplate.
Delegate listeners will be called in their registration order.
- Since:
- 7.0
- Author:
- Mahmoud Ben Hassine, Juergen Hoeller, Sam Brannen
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a newCompositeRetryListener.CompositeRetryListener(List<RetryListener> listeners) Create a newCompositeRetryListenerwith the supplied list of delegates. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(RetryListener listener) Add a new listener to the list of delegates.voidbeforeRetry(RetryPolicy retryPolicy, Retryable<?> retryable, RetryState retryState) Called before every retry attempt.voidonRetryableExecution(RetryPolicy retryPolicy, Retryable<?> retryable, RetryState retryState) Called after every attempt, including the initial invocation.voidonRetryFailure(RetryPolicy retryPolicy, Retryable<?> retryable, Throwable throwable) Called after every failed retry attempt.voidonRetryPolicyExhaustion(RetryPolicy retryPolicy, Retryable<?> retryable, RetryException exception) Called if theRetryPolicyis exhausted.voidonRetryPolicyInterruption(RetryPolicy retryPolicy, Retryable<?> retryable, RetryException exception) Called if theRetryPolicyis interrupted between retry attempts.voidonRetryPolicyTimeout(RetryPolicy retryPolicy, Retryable<?> retryable, RetryException exception) Called if the configured timeout for aRetryPolicyis exceeded.voidonRetrySuccess(RetryPolicy retryPolicy, Retryable<?> retryable, @Nullable Object result) Called after the first successful retry attempt.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface RetryListener
beforeRetry
-
Constructor Details
-
CompositeRetryListener
public CompositeRetryListener()Create a newCompositeRetryListener.- See Also:
-
CompositeRetryListener
Create a newCompositeRetryListenerwith the supplied list of delegates.- Parameters:
listeners- the list of delegate listeners to register; must not be empty
-
-
Method Details
-
addListener
Add a new listener to the list of delegates.- Parameters:
listener- the listener to add
-
onRetryableExecution
public void onRetryableExecution(RetryPolicy retryPolicy, Retryable<?> retryable, RetryState retryState) Description copied from interface:RetryListenerCalled 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().- Specified by:
onRetryableExecutionin interfaceRetryListener- Parameters:
retryPolicy- theRetryPolicyretryable- theRetryableoperationretryState- the current state of retry processing (this is a live instance reflecting the current state; not intended to be stored)- See Also:
-
beforeRetry
Description copied from interface:RetryListenerCalled before every retry attempt.For a corresponding callback after every retry attempt, consider
RetryListener.onRetryableExecution(RetryPolicy, Retryable, RetryState), ignoring the initial attempt through a correspondingRetryState.getRetryCount()check.- Specified by:
beforeRetryin interfaceRetryListener- Parameters:
retryPolicy- theRetryPolicyretryable- theRetryableoperationretryState- the current state of retry processing (this is a live instance reflecting the current state; not intended to be stored)- See Also:
-
onRetrySuccess
public void onRetrySuccess(RetryPolicy retryPolicy, Retryable<?> retryable, @Nullable Object result) Description copied from interface:RetryListenerCalled after the first successful retry attempt.- Specified by:
onRetrySuccessin interfaceRetryListener- Parameters:
retryPolicy- theRetryPolicyretryable- theRetryableoperationresult- the result of theRetryableoperation
-
onRetryFailure
Description copied from interface:RetryListenerCalled after every failed retry attempt.- Specified by:
onRetryFailurein interfaceRetryListener- Parameters:
retryPolicy- theRetryPolicyretryable- theRetryableoperationthrowable- the exception thrown by theRetryableoperation
-
onRetryPolicyExhaustion
public void onRetryPolicyExhaustion(RetryPolicy retryPolicy, Retryable<?> retryable, RetryException exception) Description copied from interface:RetryListenerCalled if theRetryPolicyis exhausted.- Specified by:
onRetryPolicyExhaustionin interfaceRetryListener- 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
public void onRetryPolicyInterruption(RetryPolicy retryPolicy, Retryable<?> retryable, RetryException exception) Description copied from interface:RetryListenerCalled if theRetryPolicyis interrupted between retry attempts.- Specified by:
onRetryPolicyInterruptionin interfaceRetryListener- 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
public void onRetryPolicyTimeout(RetryPolicy retryPolicy, Retryable<?> retryable, RetryException exception) Description copied from interface:RetryListenerCalled if the configured timeout for aRetryPolicyis exceeded.- Specified by:
onRetryPolicyTimeoutin interfaceRetryListener- 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:
-