org.springframework.batch.retry.policy
Class AbstractStatefulRetryPolicy
java.lang.Object
org.springframework.batch.retry.policy.AbstractStatefulRetryPolicy
- All Implemented Interfaces:
- RetryPolicy
- Direct Known Subclasses:
- RecoveryCallbackRetryPolicy
public abstract class AbstractStatefulRetryPolicy
- extends Object
- implements RetryPolicy
Base class for stateful retry policies: those that operate in the context of
a callback that is called once per retry execution (usually to enforce that
it is only called once per transaction). Stateful policies need to remember
the context for the operation that failed (e.g. the data item that was being
processed), and decide based on its history what to do in the current
context. For example: the retry operation includes receiving a message, and
we need it to roll back and be re-delivered so that we can have another crack
at it.
- Author:
- Dave Syer
- See Also:
RetryPolicy.handleRetryExhausted(RetryContext)
,
AbstractStatelessRetryPolicy
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
retryContextCache
protected RetryContextCache retryContextCache
AbstractStatefulRetryPolicy
public AbstractStatefulRetryPolicy()
setRetryContextCache
public void setRetryContextCache(RetryContextCache retryContextCache)
- Optional setter for the retry context cache. The default value is a
MapRetryContextCache
.
- Parameters:
retryContextCache
-
handleRetryExhausted
public Object handleRetryExhausted(RetryContext context)
throws ExhaustedRetryException
- Return null. Subclasses should provide a recovery path if possible.
- Specified by:
handleRetryExhausted
in interface RetryPolicy
- Parameters:
context
- the current retry context.
- Returns:
- an appropriate value possibly from the callback.
- Throws:
ExhaustedRetryException
- if there is no recovery path.- See Also:
RetryPolicy.handleRetryExhausted(org.springframework.batch.retry.RetryContext)
shouldRethrow
public boolean shouldRethrow(RetryContext context)
- For a stateful policy the default is to always rethrow. This is the
cautious approach: we assume that the failed processing may have written
data to a transactional resource, so we rethrow and force a rollback. Any
recovery path that may be available has to be taken on the next attempt,
before any processing has taken place.
- Specified by:
shouldRethrow
in interface RetryPolicy
- Parameters:
context
- the current context.
- Returns:
- true unless the last exception registered was recoverable.
setRecoverableExceptionClasses
public final void setRecoverableExceptionClasses(Class[] retryableExceptionClasses)
- Set the recoverable exceptions. Any exception on the list, or subclasses
thereof, will be recoverable. If it is encountered in a retry block it
will not be rethrown. Others will be rethrown. The recovery action (if
any) is left to subclasses - normally they would override
handleRetryExhausted(RetryContext)
.
- Parameters:
retryableExceptionClasses
- defaults to Exception
.
recoverForException
protected boolean recoverForException(Throwable ex)
Copyright © 2009 SpringSource. All Rights Reserved.