org.springframework.batch.core.step.item
Class BatchRetryTemplate

java.lang.Object
  extended by org.springframework.batch.core.step.item.BatchRetryTemplate
All Implemented Interfaces:
RetryOperations

public class BatchRetryTemplate
extends Object
implements RetryOperations

A special purpose retry template that deals specifically with multi-valued stateful retry. This is useful in the case where the operation to be retried operates on multiple items, and when it fails there is no way to decide which (if any) of the items was responsible. The RetryState used in the execute methods is composite, and when a failure occurs, all of the keys in the composite are "tarred with the same brush". Subsequent attempts to execute with any of the keys that have failed previously results in a new attempt and the previous state is used to check the RetryPolicy. If one of the failed items eventually succeeds then the others in the current composite for that attempt will be cleared from the context cache (as normal), but there may still be entries in the cache for the original failed items. This might mean that an item that did not cause a failure is never retried because other items in the same batch fail fatally first.

Author:
Dave Syer

Constructor Summary
BatchRetryTemplate()
           
 
Method Summary
static List<RetryState> createState(List<?> keys)
           
static List<RetryState> createState(List<?> keys, Classifier<? super Throwable,Boolean> classifier)
           
<T> T
execute(RetryCallback<T> retryCallback)
          Execute the supplied RetryCallback with the configured retry semantics.
<T> T
execute(RetryCallback<T> retryCallback, Collection<RetryState> states)
           
<T> T
execute(RetryCallback<T> retryCallback, RecoveryCallback<T> recoveryCallback)
          Execute the supplied RetryCallback with a fallback on exhausted retry to the RecoveryCallback.
<T> T
execute(RetryCallback<T> retryCallback, RecoveryCallback<T> recoveryCallback, Collection<RetryState> states)
           
<T> T
execute(RetryCallback<T> retryCallback, RecoveryCallback<T> recoveryCallback, RetryState retryState)
          A stateful retry with a recovery path.
<T> T
execute(RetryCallback<T> retryCallback, RetryState retryState)
          A simple stateful retry.
 void registerListener(RetryListener listener)
           
 void setBackOffPolicy(BackOffPolicy backOffPolicy)
           
 void setListeners(RetryListener[] listeners)
           
 void setRetryContextCache(RetryContextCache retryContextCache)
           
 void setRetryPolicy(RetryPolicy retryPolicy)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BatchRetryTemplate

public BatchRetryTemplate()
Method Detail

execute

public <T> T execute(RetryCallback<T> retryCallback,
                     Collection<RetryState> states)
          throws ExhaustedRetryException,
                 Exception
Throws:
ExhaustedRetryException
Exception

execute

public <T> T execute(RetryCallback<T> retryCallback,
                     RecoveryCallback<T> recoveryCallback,
                     Collection<RetryState> states)
          throws ExhaustedRetryException,
                 Exception
Throws:
ExhaustedRetryException
Exception

execute

public final <T> T execute(RetryCallback<T> retryCallback,
                           RecoveryCallback<T> recoveryCallback,
                           RetryState retryState)
                throws Exception,
                       ExhaustedRetryException
Description copied from interface: RetryOperations
A stateful retry with a recovery path. Execute the supplied RetryCallback with a fallback on exhausted retry to the RecoveryCallback and a target object for the retry attempt identified by the DefaultRetryState.

Specified by:
execute in interface RetryOperations
Returns:
the value returned by the RetryCallback upon successful invocation, and that returned by the RecoveryCallback otherwise.
Throws:
Exception - any Exception raised by the RecoveryCallback upon unsuccessful retry.
ExhaustedRetryException
See Also:
RetryOperations.execute(RetryCallback, RetryState)

execute

public final <T> T execute(RetryCallback<T> retryCallback,
                           RecoveryCallback<T> recoveryCallback)
                throws Exception
Description copied from interface: RetryOperations
Execute the supplied RetryCallback with a fallback on exhausted retry to the RecoveryCallback. See implementations for configuration details.

Specified by:
execute in interface RetryOperations
Returns:
the value returned by the RetryCallback upon successful invocation, and that returned by the RecoveryCallback otherwise.
Throws:
Exception - any Exception raised by the RecoveryCallback upon unsuccessful retry.

execute

public final <T> T execute(RetryCallback<T> retryCallback,
                           RetryState retryState)
                throws Exception,
                       ExhaustedRetryException
Description copied from interface: RetryOperations
A simple stateful retry. Execute the supplied RetryCallback with a target object for the attempt identified by the DefaultRetryState. Exceptions thrown by the callback are always propagated immediately so the state is required to be able to identify the previous attempt, if there is one - hence the state is required. Normal patterns would see this method being used inside a transaction, where the callback might invalidate the transaction if it fails.

See implementations for configuration details.

Specified by:
execute in interface RetryOperations
Returns:
the value returned by the RetryCallback upon successful invocation, and that returned by the RecoveryCallback otherwise.
Throws:
Exception - any Exception raised by the RecoveryCallback.
ExhaustedRetryException - if the last attempt for this state has already been reached

execute

public final <T> T execute(RetryCallback<T> retryCallback)
                throws Exception
Description copied from interface: RetryOperations
Execute the supplied RetryCallback with the configured retry semantics. See implementations for configuration details.

Specified by:
execute in interface RetryOperations
Returns:
the value returned by the RetryCallback upon successful invocation.
Throws:
Exception - any Exception raised by the RetryCallback upon unsuccessful retry.

createState

public static List<RetryState> createState(List<?> keys)

createState

public static List<RetryState> createState(List<?> keys,
                                           Classifier<? super Throwable,Boolean> classifier)

registerListener

public void registerListener(RetryListener listener)

setBackOffPolicy

public void setBackOffPolicy(BackOffPolicy backOffPolicy)

setListeners

public void setListeners(RetryListener[] listeners)

setRetryContextCache

public void setRetryContextCache(RetryContextCache retryContextCache)

setRetryPolicy

public void setRetryPolicy(RetryPolicy retryPolicy)


Copyright © 2009 SpringSource. All Rights Reserved.