Class 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".

Dave Syer, Robert Kasanicky, Morten Andersen-Gott
See Also:
  • Constructor Details

    • FaultTolerantStepFactoryBean

      public FaultTolerantStepFactoryBean()
  • Method Details

    • 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).
      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).
      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.
      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.
      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.
      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).
      retryableExceptionClasses - the retryableExceptionClasses to set
    • setBackOffPolicy

      public void setBackOffPolicy(org.springframework.retry.backoff.BackOffPolicy backOffPolicy)
      Public setter for the BackOffPolicy.
      backOffPolicy - the BackOffPolicy to set
    • setRetryListeners

      public void setRetryListeners(org.springframework.retry.RetryListener... retryListeners)
      Public setter for the RetryListeners.
      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.
      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.
      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.
      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.
      noRollbackExceptionClasses - the exception classes to set
    • setProcessorTransactional

      public void setProcessorTransactional(boolean processorTransactional)
      processorTransactional - boolean indicates if the ItemProcessor participates in the transaction.
    • createBuilder

      protected SimpleStepBuilder<T,S> createBuilder(String name)
      createBuilder in class SimpleStepFactoryBean<T,S>
    • applyConfiguration

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