org.springframework.batch.retry.policy
Class TimeoutRetryPolicy

java.lang.Object
  extended by org.springframework.batch.retry.policy.AbstractStatelessRetryPolicy
      extended by org.springframework.batch.retry.policy.TimeoutRetryPolicy
All Implemented Interfaces:
RetryPolicy

public class TimeoutRetryPolicy
extends AbstractStatelessRetryPolicy

A RetryPolicy that allows a retry only if it hasn't timed out. The clock is started on a call to open(RetryCallback, RetryContext).

Author:
Dave Syer

Field Summary
static long DEFAULT_TIMEOUT
          Default value for timeout (milliseconds).
 
Constructor Summary
TimeoutRetryPolicy()
           
 
Method Summary
 boolean canRetry(RetryContext context)
          Only permits a retry if the timeout has not expired.
 void close(RetryContext context)
           
 RetryContext open(RetryCallback callback, 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.
 
Methods inherited from class org.springframework.batch.retry.policy.AbstractStatelessRetryPolicy
handleRetryExhausted, shouldRethrow
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TIMEOUT

public static final long DEFAULT_TIMEOUT
Default value for timeout (milliseconds).

See Also:
Constant Field Values
Constructor Detail

TimeoutRetryPolicy

public TimeoutRetryPolicy()
Method Detail

setTimeout

public void setTimeout(long timeout)
Setter for timeout. Default is DEFAULT_TIMEOUT.

Parameters:
timeout -

canRetry

public boolean canRetry(RetryContext context)
Only permits a retry if the timeout has not expired. Does not check the exception at all.

Parameters:
context - the current retry status
Returns:
true if the operation can proceed
See Also:
RetryPolicy.canRetry(org.springframework.batch.retry.RetryContext)

close

public void close(RetryContext context)
Parameters:
context - a retry status created by the RetryPolicy.open(RetryCallback, RetryContext) method of this manager.

open

public RetryContext open(RetryCallback callback,
                         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.

Parameters:
callback - the RetryCallback that will execute the unit of work for this retry.
parent - the parent context if we are in a nested retry.
Returns:
a RetryContext object specific to this manager.

registerThrowable

public void registerThrowable(RetryContext context,
                              Throwable throwable)
                       throws TerminatedRetryException
Description copied from interface: RetryPolicy
Called once per retry attempt, after the callback fails.

Parameters:
context - the current status object.
Throws:
TerminatedRetryException - if the status is set to terminate only.


Copyright © 2009 SpringSource. All Rights Reserved.