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
FieldsModifier and TypeFieldDescriptionstatic final longDefault value for timeout (milliseconds).Fields inherited from interface org.springframework.retry.RetryPolicy
NO_MAXIMUM_ATTEMPTS_SET -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance with the timeout set toDEFAULT_TIMEOUT.TimeoutRetryPolicy(long timeout) Create a new instance with a configurable timeout. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanRetry(RetryContext context) Only permits a retry if the timeout has not expired.voidclose(RetryContext context) longThe value of the timeout.open(RetryContext parent) Acquire resources needed for the retry operation.voidregisterThrowable(RetryContext context, Throwable throwable) Called once per retry attempt, after the callback fails.voidsetTimeout(long timeout) Setter for timeout in milliseconds.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
canRetryin interfaceRetryPolicy- Parameters:
context- the current retry status- Returns:
- true if the operation can proceed
- See Also:
-
close
- Specified by:
closein interfaceRetryPolicy- Parameters:
context- a retry status created by theRetryPolicy.open(RetryContext)method of this policy.
-
open
Description copied from interface:RetryPolicyAcquire 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:
openin interfaceRetryPolicy- Parameters:
parent- the parent context if we are in a nested retry.- Returns:
- a
RetryContextobject specific to this policy.
-
registerThrowable
Description copied from interface:RetryPolicyCalled once per retry attempt, after the callback fails.- Specified by:
registerThrowablein interfaceRetryPolicy- Parameters:
context- the current status object.throwable- the exception to throw
-