org.springframework.batch.core.step.factory

## 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>

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

  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:
    `SimpleStepFactoryBean`

- - ### 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
    Constructor and Description
    `FaultTolerantStepFactoryBean()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `applyConfiguration(SimpleStepBuilder<T,S> builder)`
    `protected SimpleStepBuilder<T,S>` | `createBuilder(java.lang.String name)`
    `void` | `setBackOffPolicy(org.springframework.retry.backoff.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(java.util.Collection<java.lang.Class<? extends java.lang.Throwable>> noRollbackExceptionClasses)` Exception classes that are candidates for no rollback.
    `void` | `setProcessorTransactional(boolean processorTransactional)`
    `void` | `setRetryableExceptionClasses(java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.lang.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 the `RetryListener`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(java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.lang.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.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`

    - ### 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(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 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(org.springframework.retry.policy.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(java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.lang.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 the `BackOffPolicy`.
      Parameters:
        `backOffPolicy` - the `BackOffPolicy` to set

    - #### setRetryListeners

          public void setRetryListeners(org.springframework.retry.RetryListener... retryListeners)

      Public setter for the `RetryListener`s.
      Parameters:
        `retryListeners` - the `RetryListener`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

          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(java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.lang.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(java.util.Collection<java.lang.Class<? extends java.lang.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` - boolean indicates if the `ItemProcessor` participates in the transaction.

    - #### createBuilder

          protected SimpleStepBuilder<T,S> createBuilder(java.lang.String name)

      Overrides:
        `createBuilder` in class `SimpleStepFactoryBean<T,S>`

    - #### applyConfiguration

          protected void applyConfiguration(SimpleStepBuilder<T,S> builder)

      Overrides:
        `applyConfiguration` in class `SimpleStepFactoryBean<T,S>`