org.springframework.batch.retry.policy
Class ItemWriterRetryPolicy

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

public class ItemWriterRetryPolicy
extends AbstractStatefulRetryPolicy

A RetryPolicy that detects an ItemWriterRetryCallback 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 ItemWriterRetryCallback 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
ItemWriterRetryPolicy()
          Default constructor.
ItemWriterRetryPolicy(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.
protected  boolean hasFailed(FailedItemIdentifier failedItemIdentifier, Object key)
          Extension point for cases where it is possible to avoid a cache hit by inspecting the item to determine if could ever have been seen before.
 RetryContext open(RetryCallback callback, RetryContext parent)
          Create a new context for the execution of the callback, which must be an instance of ItemWriterRetryCallback.
 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

ItemWriterRetryPolicy

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

Parameters:
delegate -

ItemWriterRetryPolicy

public ItemWriterRetryPolicy()
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 ItemWriterRetryCallback.

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 Exception
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:
Exception - if there is no recovery path.
See Also:
AbstractStatefulRetryPolicy.handleRetryExhausted(org.springframework.batch.retry.RetryContext)

hasFailed

protected boolean hasFailed(FailedItemIdentifier failedItemIdentifier,
                            Object key)
Extension point for cases where it is possible to avoid a cache hit by inspecting the item to determine if could ever have been seen before. In a messaging environment where the item is a message, it can be inspected to see if it has been delivered before.
The default implementation of this method checks for a non-null FailedItemIdentifier. Otherwise we just check the cache for the item key.

Parameters:
failedItemIdentifier -
key -


Copyright © 2008 SpringSource. All Rights Reserved.