Package org.springframework.retry.policy
Class TimeoutRetryPolicy
java.lang.Object
org.springframework.retry.policy.TimeoutRetryPolicy
- All Implemented Interfaces:
Serializable
,RetryPolicy
A
RetryPolicy
that allows a retry only if it hasn't timed out. The clock is
started on a call to open(RetryContext)
.- Author:
- Dave Syer
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
Default value for timeout (milliseconds).Fields inherited from interface org.springframework.retry.RetryPolicy
NO_MAXIMUM_ATTEMPTS_SET
-
Constructor Summary
ConstructorDescriptionCreate a new instance with the timeout set toDEFAULT_TIMEOUT
.TimeoutRetryPolicy
(long timeout) Create a new instance with a configurable timeout. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canRetry
(RetryContext context) Only permits a retry if the timeout has not expired.void
close
(RetryContext context) long
The value of the timeout.open
(RetryContext parent) Acquire resources needed for the retry operation.void
registerThrowable
(RetryContext context, Throwable throwable) Called once per retry attempt, after the callback fails.void
setTimeout
(long timeout) Setter for timeout in milliseconds.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.retry.RetryPolicy
getMaxAttempts
-
Field Details
-
DEFAULT_TIMEOUT
public static final long DEFAULT_TIMEOUTDefault value for timeout (milliseconds).- See Also:
-
-
Constructor Details
-
TimeoutRetryPolicy
public TimeoutRetryPolicy()Create a new instance with the timeout set toDEFAULT_TIMEOUT
. -
TimeoutRetryPolicy
public TimeoutRetryPolicy(long timeout) Create a new instance with a configurable timeout.- Parameters:
timeout
- timeout in milliseconds- Since:
- 2.0.2
-
-
Method Details
-
setTimeout
public void setTimeout(long timeout) Setter for timeout in milliseconds. Default isDEFAULT_TIMEOUT
.- Parameters:
timeout
- how long to wait until a timeout
-
getTimeout
public long getTimeout()The value of the timeout.- Returns:
- the timeout in milliseconds
-
canRetry
Only permits a retry if the timeout has not expired. Does not check the exception at all.- Specified by:
canRetry
in interfaceRetryPolicy
- Parameters:
context
- the current retry status- Returns:
- true if the operation can proceed
- See Also:
-
close
- Specified by:
close
in interfaceRetryPolicy
- Parameters:
context
- a retry status created by theRetryPolicy.open(RetryContext)
method of this policy.
-
open
Description copied from interface:RetryPolicy
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.- 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.
-
registerThrowable
Description copied from interface:RetryPolicy
Called once per retry attempt, after the callback fails.- Specified by:
registerThrowable
in interfaceRetryPolicy
- Parameters:
context
- the current status object.throwable
- the exception to throw
-