Class TimeoutRetryPolicy

java.lang.Object
org.springframework.retry.policy.TimeoutRetryPolicy
All Implemented Interfaces:
Serializable, RetryPolicy

public class TimeoutRetryPolicy extends Object implements 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 Details

    • DEFAULT_TIMEOUT

      public static final long DEFAULT_TIMEOUT
      Default value for timeout (milliseconds).
      See Also:
  • Constructor Details

    • TimeoutRetryPolicy

      public TimeoutRetryPolicy()
      Create a new instance with the timeout set to DEFAULT_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 is DEFAULT_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

      public boolean canRetry(RetryContext context)
      Only permits a retry if the timeout has not expired. Does not check the exception at all.
      Specified by:
      canRetry in interface RetryPolicy
      Parameters:
      context - the current retry status
      Returns:
      true if the operation can proceed
      See Also:
    • close

      public void close(RetryContext context)
      Specified by:
      close in interface RetryPolicy
      Parameters:
      context - a retry status created by the RetryPolicy.open(RetryContext) method of this policy.
    • open

      public RetryContext open(RetryContext parent)
      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 interface RetryPolicy
      Parameters:
      parent - the parent context if we are in a nested retry.
      Returns:
      a RetryContext object specific to this policy.
    • registerThrowable

      public void registerThrowable(RetryContext context, Throwable throwable)
      Description copied from interface: RetryPolicy
      Called once per retry attempt, after the callback fails.
      Specified by:
      registerThrowable in interface RetryPolicy
      Parameters:
      context - the current status object.
      throwable - the exception to throw