org.springframework.batch.core.step.item
Class FaultTolerantStepFactoryBean<T,S>

java.lang.Object
  extended by org.springframework.batch.core.step.item.SimpleStepFactoryBean<T,S>
      extended by org.springframework.batch.core.step.item.FaultTolerantStepFactoryBean<T,S>
All Implemented Interfaces:
BeanNameAware, FactoryBean

public class FaultTolerantStepFactoryBean<T,S>
extends SimpleStepFactoryBean<T,S>

Factory bean for step that provides options for configuring skip behaviour. User can set setSkipLimit(int) to set how many exceptions of #setSkippableExceptionClasses(Collection) types are tolerated. #setFatalExceptionClasses(Collection) will cause immediate termination of job - they are treated as higher priority than #setSkippableExceptionClasses(Collection), so the two lists don't need to be exclusive. Skippable exceptions on write will by default cause transaction rollback - to avoid rollback for specific exception class include it in the transaction attribute as "no rollback for".

Author:
Dave Syer, Robert Kasanicky, Morten Andersen-Gott
See Also:
SimpleStepFactoryBean

Field Summary
 
Fields inherited from class org.springframework.batch.core.step.item.SimpleStepFactoryBean
logger
 
Constructor Summary
FaultTolerantStepFactoryBean()
           
 
Method Summary
protected  void applyConfiguration(TaskletStep step)
           
protected  SimpleChunkProcessor<T,S> configureChunkProcessor()
          Extension point for creating appropriate ChunkProcessor.
protected  SimpleChunkProvider<T> configureChunkProvider()
          Extension point for creating appropriate ChunkProvider.
protected  SkipPolicy createSkipPolicy()
           
protected  Classifier<Throwable,Boolean> getRollbackClassifier()
          Convenience method for subclasses to get an exception classifier based on the provided transaction attributes.
protected  TransactionAttribute getTransactionAttribute()
          Getter for the TransactionAttribute for subclasses only.
protected  void registerChunkListeners(TaskletStep step, StepListener listener)
           
protected  void registerStreams(TaskletStep step, ItemStream[] streams)
          Register the streams with the step.
 void setBackOffPolicy(BackOffPolicy backOffPolicy)
          Public setter for the BackOffPolicy.
 void setCacheCapacity(int cacheCapacity)
          Public setter for the capacity of the cache in the retry policy.
 void setKeyGenerator(KeyGenerator keyGenerator)
          The KeyGenerator to use to identify failed items across rollback.
 void setNoRollbackExceptionClasses(Collection<Class<? extends Throwable>> noRollbackExceptionClasses)
          Exception classes that are candidates for no rollback.
 void setProcessorTransactional(boolean processorTransactional)
           
 void setRetryableExceptionClasses(Map<Class<? extends Throwable>,Boolean> retryableExceptionClasses)
          Public setter for the retryable exceptions classifier map (from throwable class to boolean, true is retryable).
 void setRetryContextCache(RetryContextCache retryContextCache)
          Override the default retry context cache for retry of chunk processing.
 void setRetryLimit(int retryLimit)
          Public setter for the retry limit.
 void setRetryListeners(RetryListener... retryListeners)
          Public setter for the RetryListeners.
 void setRetryPolicy(RetryPolicy retryPolicy)
          Setter for the retry policy.
 void setSkipLimit(int skipLimit)
          A limit that determines skip policy.
 void setSkippableExceptionClasses(Map<Class<? extends Throwable>,Boolean> exceptionClasses)
          Exception classes that when raised won't crash the job but will result in the item which handling caused the exception being skipped.
 void setSkipPolicy(SkipPolicy skipPolicy)
          A SkipPolicy that determines the outcome of an exception when processing an item.
 
Methods inherited from class org.springframework.batch.core.step.item.SimpleStepFactoryBean
getChunkOperations, getCommitInterval, getExceptionHandler, getItemProcessor, getItemReader, getItemWriter, getListeners, getName, getObject, getObjectType, getStepOperations, getTaskExecutor, isReaderTransactionalQueue, isSingleton, setAllowStartIfComplete, setBeanName, setChunkCompletionPolicy, setChunkOperations, setCommitInterval, setExceptionHandler, setIsolation, setIsReaderTransactionalQueue, setItemProcessor, setItemReader, setItemWriter, setJobRepository, setListeners, setPropagation, setSingleton, setStartLimit, setStepOperations, setStreams, setTaskExecutor, setThrottleLimit, setTransactionManager, setTransactionTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FaultTolerantStepFactoryBean

public FaultTolerantStepFactoryBean()
Method Detail

setKeyGenerator

public void setKeyGenerator(KeyGenerator keyGenerator)
The KeyGenerator to use to identify failed items across rollback. Not used in the case of the transactional queue flag being false (the default).

Parameters:
keyGenerator - the KeyGenerator to set

setRetryPolicy

public void setRetryPolicy(RetryPolicy retryPolicy)
Setter for the retry policy. If this is specified the other retry properties are ignored (retryLimit, backOffPolicy, retryableExceptionClasses).

Parameters:
retryPolicy - a stateless RetryPolicy

setRetryLimit

public void setRetryLimit(int retryLimit)
Public setter for the retry limit. Each item can be retried up to this limit. Note this limit includes the initial attempt to process the item, therefore retryLimit == 1 by default.

Parameters:
retryLimit - the retry limit to set, must be greater or equal to 1.

setCacheCapacity

public void setCacheCapacity(int cacheCapacity)
Public setter for the capacity of the cache in the retry policy. If more items than this fail without being skipped or recovered an exception will be thrown. This is to guard against inadvertent infinite loops generated by item identity problems.
The default value should be high enough and more for most purposes. To breach the limit in a single-threaded step typically you have to have this many failures in a single transaction. Defaults to the value in the MapRetryContextCache.
This property is ignored if the setRetryContextCache(RetryContextCache) is set directly.

Parameters:
cacheCapacity - the cache capacity to set (greater than 0 else ignored)

setRetryContextCache

public void setRetryContextCache(RetryContextCache retryContextCache)
Override the default retry context cache for retry of chunk processing. If this property is set then setCacheCapacity(int) is ignored.

Parameters:
retryContextCache - the RetryContextCache to set

setRetryableExceptionClasses

public void setRetryableExceptionClasses(Map<Class<? extends Throwable>,Boolean> retryableExceptionClasses)
Public setter for the retryable exceptions classifier map (from throwable class to boolean, true is retryable).

Parameters:
retryableExceptionClasses - the retryableExceptionClasses to set

setBackOffPolicy

public void setBackOffPolicy(BackOffPolicy backOffPolicy)
Public setter for the BackOffPolicy.

Parameters:
backOffPolicy - the BackOffPolicy to set

setRetryListeners

public void setRetryListeners(RetryListener... retryListeners)
Public setter for the RetryListeners.

Parameters:
retryListeners - the RetryListeners to set

setSkipLimit

public void setSkipLimit(int skipLimit)
A limit that determines skip policy. If this value is positive then an exception in chunk processing will cause the item to be skipped and no exception propagated until the limit is reached. If it is zero then all exceptions will be propagated from the chunk and cause the step to abort.

Parameters:
skipLimit - the value to set. Default is 0 (never skip).

setSkipPolicy

public void setSkipPolicy(SkipPolicy skipPolicy)
A SkipPolicy that determines the outcome of an exception when processing an item. Overrides the skipLimit. The skippableExceptionClasses are also ignored if this is set.

Parameters:
skipPolicy - the SkipPolicy to set

setSkippableExceptionClasses

public void setSkippableExceptionClasses(Map<Class<? extends Throwable>,Boolean> exceptionClasses)
Exception classes that when raised won't crash the job but will result in the item which handling caused the exception being skipped. Any exception which is marked for "no rollback" is also skippable, but not vice versa. Remember to set the skip limit as well.

Defaults to all no exception.

Parameters:
exceptionClasses - defaults to Exception

setNoRollbackExceptionClasses

public void setNoRollbackExceptionClasses(Collection<Class<? extends Throwable>> noRollbackExceptionClasses)
Exception classes that are candidates for no rollback. The Step can not honour the no rollback hint in all circumstances, but any exception on this list is counted as skippable, so even if there has to be a rollback, then the step will not fail as long as the skip limit is not breached.

Defaults is empty.

Parameters:
noRollbackExceptionClasses - the exception classes to set

setProcessorTransactional

public void setProcessorTransactional(boolean processorTransactional)
Parameters:
processorTransactional -

getRollbackClassifier

protected Classifier<Throwable,Boolean> getRollbackClassifier()
Convenience method for subclasses to get an exception classifier based on the provided transaction attributes.

Returns:
an exception classifier: maps to true if an exception should cause rollback

getTransactionAttribute

protected TransactionAttribute getTransactionAttribute()
Getter for the TransactionAttribute for subclasses only.

Overrides:
getTransactionAttribute in class SimpleStepFactoryBean<T,S>
Returns:
the transactionAttribute

applyConfiguration

protected void applyConfiguration(TaskletStep step)
Overrides:
applyConfiguration in class SimpleStepFactoryBean<T,S>

registerStreams

protected void registerStreams(TaskletStep step,
                               ItemStream[] streams)
Register the streams with the step.

Overrides:
registerStreams in class SimpleStepFactoryBean<T,S>
Parameters:
step - the TaskletStep
streams - the streams to register

configureChunkProvider

protected SimpleChunkProvider<T> configureChunkProvider()
Description copied from class: SimpleStepFactoryBean
Extension point for creating appropriate ChunkProvider. Return value must subclass SimpleChunkProvider due to listener registration.

Overrides:
configureChunkProvider in class SimpleStepFactoryBean<T,S>
Returns:
ChunkProvider configured for fault-tolerance.

createSkipPolicy

protected SkipPolicy createSkipPolicy()
Returns:

configureChunkProcessor

protected SimpleChunkProcessor<T,S> configureChunkProcessor()
Description copied from class: SimpleStepFactoryBean
Extension point for creating appropriate ChunkProcessor. Return value must subclass SimpleChunkProcessor due to listener registration.

Overrides:
configureChunkProcessor in class SimpleStepFactoryBean<T,S>
Returns:
ChunkProcessor configured for fault-tolerance.

registerChunkListeners

protected void registerChunkListeners(TaskletStep step,
                                      StepListener listener)
Overrides:
registerChunkListeners in class SimpleStepFactoryBean<T,S>


Copyright © 2013 SpringSource. All Rights Reserved.