org.springframework.batch.retry.policy
Class RecoveryCallbackRetryPolicy

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

public class RecoveryCallbackRetryPolicy
extends AbstractStatefulRetryPolicy

A RetryPolicy that detects an RecoveryRetryCallback when it opens a new context, and uses it to make sure the item is in place for later decisions about how to retry or backoff. The callback should be an instance of RecoveryRetryCallback otherwise an exception will be thrown when the context is created.

Author:
Dave Syer

Field Summary
static String EXHAUSTED
           
protected  org.apache.commons.logging.Log logger
           
 
Fields inherited from class org.springframework.batch.retry.policy.AbstractStatefulRetryPolicy
retryContextCache
 
Constructor Summary
RecoveryCallbackRetryPolicy()
          Default constructor.
RecoveryCallbackRetryPolicy(RetryPolicy delegate)
          Convenience constructor to set delegate on init.
 
Method Summary
 boolean canRetry(RetryContext context)
          Check the history of this item, and if it has reached the retry limit, then return false.
 void close(RetryContext context)
          Delegates to the delegate context.
 Object handleRetryExhausted(RetryContext context)
          Call recovery path (if any) and clean up context history.
 RetryContext open(RetryCallback callback, RetryContext parent)
          Create a new context for the execution of the callback, which must be an instance of RecoveryRetryCallback.
 void registerThrowable(RetryContext context, Throwable throwable)
          If canRetry(RetryContext) is false then take remedial action (if implemented by subclasses), and remove the current item from the history.
 void setDelegate(RetryPolicy delegate)
          Setter for delegate.
 
Methods inherited from class org.springframework.batch.retry.policy.AbstractStatefulRetryPolicy
recoverForException, setRecoverableExceptionClasses, setRetryContextCache, shouldRethrow
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected org.apache.commons.logging.Log logger

EXHAUSTED

public static final String EXHAUSTED
Constructor Detail

RecoveryCallbackRetryPolicy

public RecoveryCallbackRetryPolicy(RetryPolicy delegate)
Convenience constructor to set delegate on init.

Parameters:
delegate -

RecoveryCallbackRetryPolicy

public RecoveryCallbackRetryPolicy()
Default constructor. Creates a new SimpleRetryPolicy for the delegate.

Method Detail

setDelegate

public void setDelegate(RetryPolicy delegate)
Setter for delegate.

Parameters:
delegate -

canRetry

public boolean canRetry(RetryContext context)
Check the history of this item, and if it has reached the retry limit, then return false.

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)
Delegates to the delegate context.

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

open

public RetryContext open(RetryCallback callback,
                         RetryContext parent)
Create a new context for the execution of the callback, which must be an instance of RecoveryRetryCallback.

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.
Throws:
IllegalStateException - if the callback is not of the required type.
See Also:
RetryPolicy.open(org.springframework.batch.retry.RetryCallback, RetryContext)

registerThrowable

public void registerThrowable(RetryContext context,
                              Throwable throwable)
                       throws TerminatedRetryException
If canRetry(RetryContext) is false then take remedial action (if implemented by subclasses), and remove the current item from the history.

Parameters:
context - the current status object.
Throws:
TerminatedRetryException - if the status is set to terminate only.
See Also:
RetryPolicy.registerThrowable(org.springframework.batch.retry.RetryContext, java.lang.Throwable)

handleRetryExhausted

public Object handleRetryExhausted(RetryContext context)
                            throws ExhaustedRetryException
Call recovery path (if any) and clean up context history.

Specified by:
handleRetryExhausted in interface RetryPolicy
Overrides:
handleRetryExhausted in class AbstractStatefulRetryPolicy
Parameters:
context - the current retry context.
Returns:
an appropriate value possibly from the callback.
Throws:
ExhaustedRetryException - if there is no recovery path.
See Also:
AbstractStatefulRetryPolicy.handleRetryExhausted(org.springframework.batch.retry.RetryContext)


Copyright © 2009 SpringSource. All Rights Reserved.