org.springframework.batch.retry.support
Class RetryTemplate

java.lang.Object
  extended by org.springframework.batch.retry.support.RetryTemplate
All Implemented Interfaces:
RetryOperations

public class RetryTemplate
extends Object
implements RetryOperations

Template class that simplifies the execution of operations with retry semantics.
Retryable operations are encapsulated in implementations of the RetryCallback interface and are executed using one of the supplied execute(org.springframework.batch.retry.RetryCallback) methods.
By default, an operation is retried if is throws any Exception or subclass of Exception. This behaviour can be changed by using the setRetryPolicy(RetryPolicy) method.
Also by default, each operation is retried for a maximum of three attempts with no back off in between. This behaviour can be configured using the setRetryPolicy(RetryPolicy) and setBackOffPolicy(BackOffPolicy) properties. The BackOffPolicy controls how long the pause is between each individual retry attempt.
This class is thread-safe and suitable for concurrent access when executing operations and when performing configuration changes. As such, it is possible to change the number of retries on the fly, as well as the BackOffPolicy used and no in progress retryable operations will be affected.

Author:
Rob Harrop, Dave Syer

Field Summary
protected  org.apache.commons.logging.Log logger
           
 
Constructor Summary
RetryTemplate()
           
 
Method Summary
 Object execute(RetryCallback callback)
          Keep executing the callback until it either succeeds or the policy dictates that we stop, in which case the most recent exception thrown by the callback will be rethrown.
 void registerListener(RetryListener listener)
          Register an additional listener.
 void setBackOffPolicy(BackOffPolicy backOffPolicy)
          Setter for BackOffPolicy.
 void setListeners(RetryListener[] listeners)
          Setter for listeners.
 void setRetryPolicy(RetryPolicy retryPolicy)
          Setter for RetryPolicy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

RetryTemplate

public RetryTemplate()
Method Detail

setListeners

public void setListeners(RetryListener[] listeners)
Setter for listeners. The listeners are executed before and after a retry block (i.e. before and after all the attempts), and on an error (every attempt).

Parameters:
listeners -
See Also:
RetryListener

registerListener

public void registerListener(RetryListener listener)
Register an additional listener.

Parameters:
listener -
See Also:
setListeners(RetryListener[])

setBackOffPolicy

public void setBackOffPolicy(BackOffPolicy backOffPolicy)
Setter for BackOffPolicy.

Parameters:
backOffPolicy -

setRetryPolicy

public void setRetryPolicy(RetryPolicy retryPolicy)
Setter for RetryPolicy.

Parameters:
retryPolicy -

execute

public final Object execute(RetryCallback callback)
                     throws Exception
Keep executing the callback until it either succeeds or the policy dictates that we stop, in which case the most recent exception thrown by the callback will be rethrown.

Specified by:
execute in interface RetryOperations
Returns:
the value returned by the RetryCallback upon successful invocation.
Throws:
TerminatedRetryException - if the retry has been manually terminated through the RetryContext.
Exception - any Exception raised by the RetryCallback upon unsuccessful retry.
See Also:
RetryOperations.execute(org.springframework.batch.retry.RetryCallback)


Copyright © 2009 SpringSource. All Rights Reserved.