Class FaultTolerantStepFactoryBean<T,S>
java.lang.Object
org.springframework.batch.core.step.factory.SimpleStepFactoryBean<T,S>
org.springframework.batch.core.step.factory.FaultTolerantStepFactoryBean<T,S>
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanNameAware
,org.springframework.beans.factory.FactoryBean<Step>
Factory bean for step that provides options for configuring skip behavior. User can set
setSkipLimit(int)
to set how many exceptions of
setSkippableExceptionClasses(Map)
types are tolerated.
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:
-
Field Summary
Fields inherited from class org.springframework.batch.core.step.factory.SimpleStepFactoryBean
logger
Fields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
applyConfiguration
(SimpleStepBuilder<T, S> builder) protected SimpleStepBuilder<T,
S> createBuilder
(String name) void
setBackOffPolicy
(org.springframework.retry.backoff.BackOffPolicy backOffPolicy) Public setter for theBackOffPolicy
.void
setCacheCapacity
(int cacheCapacity) Public setter for the capacity of the cache in the retry policy.void
setKeyGenerator
(KeyGenerator keyGenerator) TheKeyGenerator
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
(org.springframework.retry.policy.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
(org.springframework.retry.RetryListener... retryListeners) Public setter for theRetryListener
s.void
setRetryPolicy
(org.springframework.retry.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) ASkipPolicy
that determines the outcome of an exception when processing an item.Methods inherited from class org.springframework.batch.core.step.factory.SimpleStepFactoryBean
getChunkOperations, getExceptionHandler, getItemProcessor, getItemReader, getItemWriter, getListeners, getName, getObject, getObjectType, getStepOperations, getTaskExecutor, getTransactionAttribute, isReaderTransactionalQueue, isSingleton, setAllowStartIfComplete, setBeanName, setChunkCompletionPolicy, setChunkOperations, setCommitInterval, setExceptionHandler, setIsolation, setIsReaderTransactionalQueue, setItemProcessor, setItemReader, setItemWriter, setJobRepository, setListeners, setPropagation, setSingleton, setStartLimit, setStepOperations, setStreams, setTaskExecutor, setThrottleLimit, setTransactionManager, setTransactionTimeout
-
Constructor Details
-
FaultTolerantStepFactoryBean
public FaultTolerantStepFactoryBean()
-
-
Method Details
-
setKeyGenerator
TheKeyGenerator
to use to identify failed items across rollback. Not used in the case of thetransactional queue flag
being false (the default).- Parameters:
keyGenerator
- theKeyGenerator
to set
-
setRetryPolicy
public void setRetryPolicy(org.springframework.retry.RetryPolicy retryPolicy) Setter for the retry policy. If this is specified the other retry properties are ignored (retryLimit, backOffPolicy, retryableExceptionClasses).- Parameters:
retryPolicy
- a statelessRetryPolicy
-
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, thereforeretryLimit == 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 theMapRetryContextCache
.
This property is ignored if thesetRetryContextCache(RetryContextCache)
is set directly.- Parameters:
cacheCapacity
- the cache capacity to set (greater than 0 else ignored)
-
setRetryContextCache
public void setRetryContextCache(org.springframework.retry.policy.RetryContextCache retryContextCache) Override the default retry context cache for retry of chunk processing. If this property is set thensetCacheCapacity(int)
is ignored.- Parameters:
retryContextCache
- theRetryContextCache
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(org.springframework.retry.backoff.BackOffPolicy backOffPolicy) Public setter for theBackOffPolicy
.- Parameters:
backOffPolicy
- theBackOffPolicy
to set
-
setRetryListeners
public void setRetryListeners(org.springframework.retry.RetryListener... retryListeners) Public setter for theRetryListener
s.- Parameters:
retryListeners
- theRetryListener
s 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
ASkipPolicy
that determines the outcome of an exception when processing an item. Overrides theskipLimit
. TheskippableExceptionClasses
are also ignored if this is set.- Parameters:
skipPolicy
- theSkipPolicy
to set
-
setSkippableExceptionClasses
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 theskip limit
as well.
Defaults to all no exception.- Parameters:
exceptionClasses
- defaults toException
-
setNoRollbackExceptionClasses
public void setNoRollbackExceptionClasses(Collection<Class<? extends Throwable>> noRollbackExceptionClasses) Exception classes that are candidates for no rollback. TheStep
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
- boolean indicates if theItemProcessor
participates in the transaction.
-
createBuilder
- Overrides:
createBuilder
in classSimpleStepFactoryBean<T,
S>
-
applyConfiguration
- Overrides:
applyConfiguration
in classSimpleStepFactoryBean<T,
S>
-