Package org.springframework.retry
Interface RetryPolicy
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
AlwaysRetryPolicy,BinaryExceptionClassifierRetryPolicy,CircuitBreakerRetryPolicy,CompositeRetryPolicy,ExceptionClassifierRetryPolicy,ExpressionRetryPolicy,MaxAttemptsRetryPolicy,NeverRetryPolicy,PredicateRetryPolicy,SimpleRetryPolicy,TimeoutRetryPolicy
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe value returned bygetMaxAttempts()when the policy doesn't provide a maximum number of attempts before failure -
Method Summary
Modifier and TypeMethodDescriptionbooleancanRetry(RetryContext context) voidclose(RetryContext context) default intCalled to understand if the policy has a fixed number of maximum attempts before failureopen(RetryContext parent) Acquire resources needed for the retry operation.voidregisterThrowable(RetryContext context, Throwable throwable) Called once per retry attempt, after the callback fails.
-
Field Details
-
NO_MAXIMUM_ATTEMPTS_SET
static final int NO_MAXIMUM_ATTEMPTS_SETThe value returned bygetMaxAttempts()when the policy doesn't provide a maximum number of attempts before failure- See Also:
-
-
Method Details
-
canRetry
- Parameters:
context- the current retry status- Returns:
- true if the operation can proceed
-
open
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
RetryContextobject specific to this policy.
-
close
- Parameters:
context- a retry status created by theopen(RetryContext)method of this policy.
-
registerThrowable
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
-