Package org.springframework.retry.policy
Class CompositeRetryPolicy
java.lang.Object
org.springframework.retry.policy.CompositeRetryPolicy
- All Implemented Interfaces:
Serializable
,RetryPolicy
A
RetryPolicy
that composes a list of other policies and delegates calls to
them in order.- Author:
- Dave Syer, Michael Minella, Emanuele Ivaldi
- See Also:
-
Field Summary
Fields inherited from interface org.springframework.retry.RetryPolicy
NO_MAXIMUM_ATTEMPTS_SET
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
canRetry
(RetryContext context) Delegate to the policies that were in operation when the context was created.void
close
(RetryContext context) Delegate to the policies that were in operation when the context was created.int
Called to understand if the policy has a fixed number of maximum attempts before failureopen
(RetryContext parent) Creates a new context that copies the existing policies and keeps a list of the contexts from each one.void
registerThrowable
(RetryContext context, Throwable throwable) Delegate to the policies that were in operation when the context was created.void
setOptimistic
(boolean optimistic) Setter for optimistic.void
setPolicies
(RetryPolicy[] policies) Setter for policies.
-
Constructor Details
-
CompositeRetryPolicy
public CompositeRetryPolicy()
-
-
Method Details
-
setOptimistic
public void setOptimistic(boolean optimistic) Setter for optimistic.- Parameters:
optimistic
- should this retry policy be optimistic
-
setPolicies
Setter for policies.- Parameters:
policies
- theRetryPolicy
policies
-
canRetry
Delegate to the policies that were in operation when the context was created. If any of them cannot retry then return false, otherwise return true.- Specified by:
canRetry
in interfaceRetryPolicy
- Parameters:
context
- theRetryContext
- Returns:
- true if the operation can proceed
- See Also:
-
close
Delegate to the policies that were in operation when the context was created. If any of them fails to close the exception is propagated (and those later in the chain are closed before re-throwing).- Specified by:
close
in interfaceRetryPolicy
- Parameters:
context
- theRetryContext
- See Also:
-
open
Creates a new context that copies the existing policies and keeps a list of the contexts from each one.- Specified by:
open
in interfaceRetryPolicy
- Parameters:
parent
- the parent context if we are in a nested retry.- Returns:
- a
RetryContext
object specific to this policy. - See Also:
-
registerThrowable
Delegate to the policies that were in operation when the context was created.- Specified by:
registerThrowable
in interfaceRetryPolicy
- Parameters:
context
- the current status object.throwable
- the exception to throw- See Also:
-
getMaxAttempts
public int getMaxAttempts()Description copied from interface:RetryPolicy
Called to understand if the policy has a fixed number of maximum attempts before failure- Specified by:
getMaxAttempts
in interfaceRetryPolicy
- Returns:
- the lower 'maximum number of attempts before failure' between all policies
that have a 'maximum number of attempts before failure' set, if at least one is
present among the policies, return
RetryPolicy.NO_MAXIMUM_ATTEMPTS_SET
otherwise
-