org.springframework.batch.retry.policy
Class SimpleRetryPolicy

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

public class SimpleRetryPolicy
extends AbstractStatelessRetryPolicy

Simple retry policy that retries a fixed number of times for a set of named exceptions (and subclasses). The number of attempts includes the initial try, so e.g.

 retryTemplate = new RetryTemplate(new SimpleRetryPolicy(3));
 retryTemplate.execute(callback);
 
will execute the callback at least once, and as many as 3 times.

Author:
Dave Syer, Rob Harrop

Field Summary
static int DEFAULT_MAX_ATTEMPTS
          The default limit to the number of attempts for a new policy.
 
Constructor Summary
SimpleRetryPolicy()
          Create a SimpleRetryPolicy with the default number of retry attempts.
SimpleRetryPolicy(int maxAttempts)
          Create a SimpleRetryPolicy with the specified number of retry attempts, and default exceptions to retry.
 
Method Summary
 boolean canRetry(RetryContext context)
          Test for retryable operation based on the status.
 void close(RetryContext status)
           
 RetryContext open(RetryCallback callback, RetryContext parent)
          Get a status object that can be used to track the current operation according to this policy.
 void registerThrowable(RetryContext context, Throwable throwable)
          Update the status with another attempted retry and the latest exception.
 void setFatalExceptionClasses(Class[] fatalExceptionClasses)
          Set the fatal exceptions.
 void setMaxAttempts(int retryAttempts)
          Setter for retry attempts.
 void setRetryableExceptionClasses(Class[] retryableExceptionClasses)
          Set the retryable exceptions.
 
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_MAX_ATTEMPTS

public static final int DEFAULT_MAX_ATTEMPTS
The default limit to the number of attempts for a new policy.

See Also:
Constant Field Values
Constructor Detail

SimpleRetryPolicy

public SimpleRetryPolicy()
Create a SimpleRetryPolicy with the default number of retry attempts.


SimpleRetryPolicy

public SimpleRetryPolicy(int maxAttempts)
Create a SimpleRetryPolicy with the specified number of retry attempts, and default exceptions to retry.

Parameters:
maxAttempts -
Method Detail

setMaxAttempts

public void setMaxAttempts(int retryAttempts)
Setter for retry attempts.

Parameters:
retryAttempts - the number of attempts before a retry becomes impossible.

canRetry

public boolean canRetry(RetryContext context)
Test for retryable operation based on the status.

Parameters:
context - the current retry status
Returns:
true if the last exception was retryable and the number of attempts so far is less than the limit.
See Also:
RetryPolicy.canRetry(org.springframework.batch.retry.RetryContext)

setRetryableExceptionClasses

public final void setRetryableExceptionClasses(Class[] retryableExceptionClasses)
Set the retryable exceptions. Any exception on the list, or subclasses thereof, will be retryable. Others will be re-thrown without retry.

Parameters:
retryableExceptionClasses - defaults to Exception.

setFatalExceptionClasses

public final void setFatalExceptionClasses(Class[] fatalExceptionClasses)
Set the fatal exceptions. Any exception on the list, or subclasses thereof, will be re-thrown without retry. This list takes precedence over the retryable list.

Parameters:
fatalExceptionClasses - defaults to Exception.

close

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

registerThrowable

public void registerThrowable(RetryContext context,
                              Throwable throwable)
Update the status with another attempted retry and the latest exception.

Parameters:
context - the current status object.
See Also:
RetryPolicy.registerThrowable(org.springframework.batch.retry.RetryContext, java.lang.Throwable)

open

public RetryContext open(RetryCallback callback,
                         RetryContext parent)
Get a status object that can be used to track the current operation according to this policy. Has to be aware of the latest exception and the number of attempts.

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.
See Also:
RetryPolicy.open(org.springframework.batch.retry.RetryCallback, RetryContext)


Copyright © 2008 SpringSource. All Rights Reserved.