org.springframework.batch.retry.callback
Class ItemWriterRetryCallback

java.lang.Object
  extended by org.springframework.batch.retry.callback.ItemWriterRetryCallback
All Implemented Interfaces:
RetryCallback

public class ItemWriterRetryCallback
extends Object
implements RetryCallback

A RetryCallback that knows about and caches an item, and attempts to process it using an ItemWriter. Used by the ItemWriterRetryPolicy to enable external retry of the item processing.

Author:
Dave Syer
See Also:
ItemWriterRetryPolicy, RetryPolicy.handleRetryExhausted(RetryContext)

Constructor Summary
ItemWriterRetryCallback(Object item, ItemWriter writer)
          Constructor with mandatory properties.
 
Method Summary
 Object doWithRetry(RetryContext context)
          Execute an operation with retry semantics.
 FailedItemIdentifier getFailedItemIdentifier()
          Accessor for the FailedItemIdentifier.
 Object getItem()
           
 ItemKeyGenerator getKeyGenerator()
          Accessor for the ItemRecoverer.
 ItemRecoverer getRecoverer()
          Accessor for the ItemRecoverer.
 void setFailedItemIdentifier(FailedItemIdentifier failedItemIdentifier)
          Public setter for the FailedItemIdentifier.
 void setKeyGenerator(ItemKeyGenerator keyGenerator)
          Public setter for the ItemKeyGenerator.
 void setRecoverer(ItemRecoverer recoverer)
          Setter for injecting optional recovery handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ItemWriterRetryCallback

public ItemWriterRetryCallback(Object item,
                               ItemWriter writer)
Constructor with mandatory properties.

Parameters:
item - the item to process
writer - the writer to use to process it
Method Detail

setRecoverer

public void setRecoverer(ItemRecoverer recoverer)
Setter for injecting optional recovery handler. If it is not injected but the reader or writer implement ItemRecoverer, one of those will be used instead (preferring the reader to the writer if both would be appropriate).

Parameters:
recoverer -

setKeyGenerator

public void setKeyGenerator(ItemKeyGenerator keyGenerator)
Public setter for the ItemKeyGenerator. If it is not injected but the reader or writer implement ItemKeyGenerator, one of those will be used instead (preferring the reader to the writer if both would be appropriate).

Parameters:
keyGenerator - the keyGenerator to set

setFailedItemIdentifier

public void setFailedItemIdentifier(FailedItemIdentifier failedItemIdentifier)
Public setter for the FailedItemIdentifier. If it is not injected but the reader or writer implement FailedItemIdentifier, one of those will be used instead (preferring the reader to the writer if both would be appropriate).

Parameters:
failedItemIdentifier - the FailedItemIdentifier to set

doWithRetry

public Object doWithRetry(RetryContext context)
                   throws Throwable
Description copied from interface: RetryCallback
Execute an operation with retry semantics. Operations should generally be idempotent, but implementations may choose to implement compensation semantics when an operation is retried.

Specified by:
doWithRetry in interface RetryCallback
Parameters:
context - the current retry context.
Returns:
the result of the successful operation.
Throws:
Throwable

getItem

public Object getItem()

getKeyGenerator

public ItemKeyGenerator getKeyGenerator()
Accessor for the ItemRecoverer. If the handler is null but the ItemWriter is an instance of ItemRecoverer, then it will be returned instead. If none of those strategies works then a default implementation of ItemKeyGenerator will be used that just returns the item.

Returns:
the ItemRecoverer.

getFailedItemIdentifier

public FailedItemIdentifier getFailedItemIdentifier()
Accessor for the FailedItemIdentifier. If the handler is null but the ItemWriter or ItemWriter is an instance of FailedItemIdentifier, then it will be returned instead. If none of those strategies works returns null.

Returns:
the FailedItemIdentifier.

getRecoverer

public ItemRecoverer getRecoverer()
Accessor for the ItemRecoverer. If the handler is null but the ItemWriter is an instance of ItemRecoverer, then it will be returned instead.

Returns:
the ItemRecoverer.


Copyright © 2008 SpringSource. All Rights Reserved.