org.springframework.batch.core.step.builder

## Class FaultTolerantStepBuilder<I,O>

- java.lang.Object
- - org.springframework.batch.core.step.builder.StepBuilderHelper<AbstractTaskletStepBuilder<B>>
  - - org.springframework.batch.core.step.builder.AbstractTaskletStepBuilder<SimpleStepBuilder<I,O>>
    - - org.springframework.batch.core.step.builder.SimpleStepBuilder<I,O>
      - - org.springframework.batch.core.step.builder.FaultTolerantStepBuilder<I,O>

- Direct Known Subclasses:
    JsrFaultTolerantStepBuilder, RemoteChunkingManagerStepBuilder, RemoteChunkingMasterStepBuilder

      public class FaultTolerantStepBuilder<I,O>
      extends SimpleStepBuilder<I,O>

  A step builder for fully fault tolerant chunk-oriented item processing steps. Extends `SimpleStepBuilder` with additional properties for retry and skip of failed items.
  Since:
    2.2
  Author:
    Dave Syer, Chris Schaefer, Michael Minella, Mahmoud Ben Hassine

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.springframework.batch.core.step.builder.StepBuilderHelper

      `StepBuilderHelper.CommonStepProperties`

  - ### Field Summary

    - ### Fields inherited from class org.springframework.batch.core.step.builder.AbstractTaskletStepBuilder

      `chunkListeners`

    - ### Fields inherited from class org.springframework.batch.core.step.builder.StepBuilderHelper

      `logger, properties`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `FaultTolerantStepBuilder(SimpleStepBuilder<I,O> parent)` Create a new builder initialized with any properties in the parent.
    `` | `FaultTolerantStepBuilder(StepBuilderHelper<?> parent)` Create a new builder initialized with any properties in the parent.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `FaultTolerantStepBuilder<I,O>` | `backOffPolicy(org.springframework.retry.backoff.BackOffPolicy backOffPolicy)` Provide a backoff policy to prevent items being retried immediately (e.g.
    `TaskletStep` | `build()` Build a step with the reader, writer, processor as provided.
    `protected ChunkProcessor<I>` | `createChunkProcessor()`
    `protected ChunkProvider<I>` | `createChunkProvider()`
    `protected BatchRetryTemplate` | `createRetryOperations()`
    `protected SkipPolicy` | `createSkipPolicy()`
    `protected Tasklet` | `createTasklet()` Create a new chunk oriented tasklet with reader, writer and processor as provided.
    `protected void` | `detectStreamInReader()`
    `FaultTolerantStepBuilder<I,O>` | `faultTolerant()` Override parent method to prevent creation of a new FaultTolerantStepBuilder
    `protected ChunkMonitor` | `getChunkMonitor()`
    `protected SkipPolicy` | `getFatalExceptionAwareProxy(SkipPolicy skipPolicy)` Wrap a `SkipPolicy` and make it consistent with known fatal exceptions.
    `protected java.util.Set<RetryListener>` | `getJsrRetryListeners()`
    `protected org.springframework.classify.Classifier<java.lang.Throwable,java.lang.Boolean>` | `getRollbackClassifier()` Convenience method to get an exception classifier based on the provided transaction attributes.
    `protected java.util.Set<SkipListener<? super I,? super O>>` | `getSkipListeners()`
    `FaultTolerantStepBuilder<I,O>` | `keyGenerator(KeyGenerator keyGenerator)` Sets the key generator for identifying retried items.
    `FaultTolerantStepBuilder<I,O>` | `listener(ChunkListener listener)` Register a chunk listener.
    `SimpleStepBuilder<I,O>` | `listener(java.lang.Object listener)` Registers objects using the annotation based listener configuration.
    `FaultTolerantStepBuilder<I,O>` | `listener(RetryListener listener)`
    `FaultTolerantStepBuilder<I,O>` | `listener(org.springframework.retry.RetryListener listener)` Register a retry listener.
    `FaultTolerantStepBuilder<I,O>` | `listener(SkipListener<? super I,? super O> listener)` Register a skip listener.
    `FaultTolerantStepBuilder<I,O>` | `noRetry(java.lang.Class<? extends java.lang.Throwable> type)` Explicitly ask for an exception (and subclasses) to be excluded from retry.
    `FaultTolerantStepBuilder<I,O>` | `noRollback(java.lang.Class<? extends java.lang.Throwable> type)` Mark this exception as ignorable during item read or processing operations.
    `FaultTolerantStepBuilder<I,O>` | `noSkip(java.lang.Class<? extends java.lang.Throwable> type)` Explicitly prevent certain exceptions (and subclasses) from being skipped.
    `FaultTolerantStepBuilder<I,O>` | `processorNonTransactional()` Mark the item processor as non-transactional (default is the opposite).
    `protected void` | `registerStepListenerAsSkipListener()`
    `FaultTolerantStepBuilder<I,O>` | `retry(java.lang.Class<? extends java.lang.Throwable> type)` Explicitly ask for an exception (and subclasses) to be retried.
    `FaultTolerantStepBuilder<I,O>` | `retryContextCache(org.springframework.retry.policy.RetryContextCache retryContextCache)` Provide an explicit retry context cache.
    `FaultTolerantStepBuilder<I,O>` | `retryLimit(int retryLimit)` The maximum number of times to try a failed item.
    `FaultTolerantStepBuilder<I,O>` | `retryPolicy(org.springframework.retry.RetryPolicy retryPolicy)` Provide an explicit retry policy instead of using the `retryLimit(int)` and retryable exceptions provided elsewhere.
    `FaultTolerantStepBuilder<I,O>` | `skip(java.lang.Class<? extends java.lang.Throwable> type)` Explicitly request certain exceptions (and subclasses) to be skipped.
    `FaultTolerantStepBuilder<I,O>` | `skipLimit(int skipLimit)` Sets the maximum number of failed items to skip before the step fails.
    `FaultTolerantStepBuilder<I,O>` | `skipPolicy(SkipPolicy skipPolicy)` Provide an explicit policy for managing skips.
    `AbstractTaskletStepBuilder<SimpleStepBuilder<I,O>>` | `stream(ItemStream stream)` Register a stream for callbacks that manage restart data.
    `AbstractTaskletStepBuilder<SimpleStepBuilder<I,O>>` | `transactionAttribute(org.springframework.transaction.interceptor.TransactionAttribute transactionAttribute)` Sets the transaction attributes for the tasklet execution.

    - ### Methods inherited from class org.springframework.batch.core.step.builder.SimpleStepBuilder

      `chunk, chunk, chunkOperations, createChunkOperations, getChunkCompletionPolicy, getChunkSize, getItemListeners, getProcessor, getReader, getWriter, isReaderTransactionalQueue, listener, listener, listener, processor, processor, reader, readerIsTransactionalQueue, registerAsStreamsAndListeners, registerStepListenerAsItemListener, writer`

    - ### Methods inherited from class org.springframework.batch.core.step.builder.AbstractTaskletStepBuilder

      `concurrent, exceptionHandler, getExceptionHandler, getStepOperations, getStreams, getTaskExecutor, getThrottleLimit, getTransactionAttribute, registerStepListenerAsChunkListener, stepOperations, taskExecutor, throttleLimit`

    - ### Methods inherited from class org.springframework.batch.core.step.builder.StepBuilderHelper

      `allowStartIfComplete, enhance, getJobRepository, getName, getTransactionManager, isAllowStartIfComplete, listener, repository, startLimit, transactionManager`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### FaultTolerantStepBuilder

          public FaultTolerantStepBuilder(StepBuilderHelper<?> parent)

      Create a new builder initialized with any properties in the parent. The parent is copied, so it can be re-used.
      Parameters:
        `parent` - a parent helper containing common step properties

    - #### FaultTolerantStepBuilder

          protected FaultTolerantStepBuilder(SimpleStepBuilder<I,O> parent)

      Create a new builder initialized with any properties in the parent. The parent is copied, so it can be re-used.
      Parameters:
        `parent` - a parent helper containing common step properties

  - ### Method Detail

    - #### build

          public TaskletStep build()

      Description copied from class: `SimpleStepBuilder`
      Build a step with the reader, writer, processor as provided.
      Overrides:
        `build` in class `SimpleStepBuilder<I,O>`
      Returns:
        a tasklet step fully configured and ready to execute
      See Also:
        `AbstractTaskletStepBuilder.build()`

    - #### registerStepListenerAsSkipListener

          protected void registerStepListenerAsSkipListener()

    - #### createTasklet

          protected Tasklet createTasklet()

      Create a new chunk oriented tasklet with reader, writer and processor as provided.
      Overrides:
        `createTasklet` in class `SimpleStepBuilder<I,O>`
      See Also:
        `SimpleStepBuilder.createTasklet()`

    - #### listener

          public SimpleStepBuilder<I,O> listener(java.lang.Object listener)

      Registers objects using the annotation based listener configuration.
      Overrides:
        `listener` in class `SimpleStepBuilder<I,O>`
      Parameters:
        `listener` - the object that has a method configured with listener annotation
      Returns:
        this for fluent chaining

    - #### listener

          public FaultTolerantStepBuilder<I,O> listener(SkipListener<? super I,? super O> listener)

      Register a skip listener.
      Parameters:
        `listener` - the listener to register
      Returns:
        this for fluent chaining

    - #### listener

          public FaultTolerantStepBuilder<I,O> listener(RetryListener listener)

    - #### listener

          public FaultTolerantStepBuilder<I,O> listener(ChunkListener listener)

      Description copied from class: `AbstractTaskletStepBuilder`
      Register a chunk listener.
      Overrides:
        `listener` in class `AbstractTaskletStepBuilder<SimpleStepBuilder<I,O>>`
      Parameters:
        `listener` - the listener to register
      Returns:
        this for fluent chaining

    - #### transactionAttribute

          public AbstractTaskletStepBuilder<SimpleStepBuilder<I,O>> transactionAttribute(org.springframework.transaction.interceptor.TransactionAttribute transactionAttribute)

      Description copied from class: `AbstractTaskletStepBuilder`
      Sets the transaction attributes for the tasklet execution. Defaults to the default values for the transaction manager, but can be manipulated to provide longer timeouts for instance.
      Overrides:
        `transactionAttribute` in class `AbstractTaskletStepBuilder<SimpleStepBuilder<I,O>>`
      Parameters:
        `transactionAttribute` - a transaction attribute set
      Returns:
        this for fluent chaining

    - #### listener

          public FaultTolerantStepBuilder<I,O> listener(org.springframework.retry.RetryListener listener)

      Register a retry listener.
      Parameters:
        `listener` - the listener to register
      Returns:
        this for fluent chaining

    - #### keyGenerator

          public FaultTolerantStepBuilder<I,O> keyGenerator(KeyGenerator keyGenerator)

      Sets the key generator for identifying retried items. Retry across transaction boundaries requires items to be identified when they are encountered again. The default strategy is to use the items themselves, relying on their own implementation to ensure that they can be identified. Often a key generator is not necessary as long as the items have reliable hash code and equals implementations, or the reader is not transactional (the default) and the item processor either is itself not transactional (not the default) or does not create new items.
      Parameters:
        `keyGenerator` - a key generator for the stateful retry
      Returns:
        this for fluent chaining

    - #### retryLimit

          public FaultTolerantStepBuilder<I,O> retryLimit(int retryLimit)

      The maximum number of times to try a failed item. Zero and one both translate to try only once and do not retry. Ignored if an explicit `retryPolicy` is set.
      Parameters:
        `retryLimit` - the retry limit (default 0)
      Returns:
        this for fluent chaining

    - #### retryPolicy

          public FaultTolerantStepBuilder<I,O> retryPolicy(org.springframework.retry.RetryPolicy retryPolicy)

      Provide an explicit retry policy instead of using the `retryLimit(int)` and retryable exceptions provided elsewhere. Can be used to retry different exceptions a different number of times, for instance.
      Parameters:
        `retryPolicy` - a retry policy
      Returns:
        this for fluent chaining

    - #### backOffPolicy

          public FaultTolerantStepBuilder<I,O> backOffPolicy(org.springframework.retry.backoff.BackOffPolicy backOffPolicy)

      Provide a backoff policy to prevent items being retried immediately (e.g. in case the failure was caused by a remote resource failure that might take some time to be resolved). Ignored if an explicit `retryPolicy` is set.
      Parameters:
        `backOffPolicy` - the back off policy to use (default no backoff)
      Returns:
        this for fluent chaining

    - #### retryContextCache

          public FaultTolerantStepBuilder<I,O> retryContextCache(org.springframework.retry.policy.RetryContextCache retryContextCache)

      Provide an explicit retry context cache. Retry is stateful across transactions in the case of failures in item processing or writing, so some information about the context for subsequent retries has to be stored.
      Parameters:
        `retryContextCache` - cache for retry contexts in between transactions (default to standard in-memory implementation)
      Returns:
        this for fluent chaining

    - #### skipLimit

          public FaultTolerantStepBuilder<I,O> skipLimit(int skipLimit)

      Sets the maximum number of failed items to skip before the step fails. Ignored if an explicit `skipPolicy(SkipPolicy)` is provided.
      Parameters:
        `skipLimit` - the skip limit to set
      Returns:
        this for fluent chaining

    - #### noSkip

          public FaultTolerantStepBuilder<I,O> noSkip(java.lang.Class<? extends java.lang.Throwable> type)

      Explicitly prevent certain exceptions (and subclasses) from being skipped.
      Parameters:
        `type` - the non-skippable exception
      Returns:
        this for fluent chaining

    - #### skip

          public FaultTolerantStepBuilder<I,O> skip(java.lang.Class<? extends java.lang.Throwable> type)

      Explicitly request certain exceptions (and subclasses) to be skipped. These exceptions (and their subclasses) might be thrown during any phase of the chunk processing (read, process, write) but separate counts are made of skips on read, process and write inside the step execution.
      Parameters:
        `type` - the exception type.
      Returns:
        this for fluent chaining

    - #### skipPolicy

          public FaultTolerantStepBuilder<I,O> skipPolicy(SkipPolicy skipPolicy)

      Provide an explicit policy for managing skips. A skip policy determines which exceptions are skippable and how many times.
      Parameters:
        `skipPolicy` - the skip policy
      Returns:
        this for fluent chaining

    - #### noRollback

          public FaultTolerantStepBuilder<I,O> noRollback(java.lang.Class<? extends java.lang.Throwable> type)

      Mark this exception as ignorable during item read or processing operations. Processing continues with no additional callbacks (use skips instead if you need to be notified). Ignored during write because there is no guarantee of skip and retry without rollback.
      Parameters:
        `type` - the exception to mark as no rollback
      Returns:
        this for fluent chaining

    - #### noRetry

          public FaultTolerantStepBuilder<I,O> noRetry(java.lang.Class<? extends java.lang.Throwable> type)

      Explicitly ask for an exception (and subclasses) to be excluded from retry.
      Parameters:
        `type` - the exception to exclude from retry
      Returns:
        this for fluent chaining

    - #### retry

          public FaultTolerantStepBuilder<I,O> retry(java.lang.Class<? extends java.lang.Throwable> type)

      Explicitly ask for an exception (and subclasses) to be retried.
      Parameters:
        `type` - the exception to retry
      Returns:
        this for fluent chaining

    - #### processorNonTransactional

          public FaultTolerantStepBuilder<I,O> processorNonTransactional()

      Mark the item processor as non-transactional (default is the opposite). If this flag is set the results of item processing are cached across transactions in between retries and during skip processing, otherwise the processor will be called in every transaction.
      Returns:
        this for fluent chaining

    - #### stream

          public AbstractTaskletStepBuilder<SimpleStepBuilder<I,O>> stream(ItemStream stream)

      Description copied from class: `AbstractTaskletStepBuilder`
      Register a stream for callbacks that manage restart data.
      Overrides:
        `stream` in class `AbstractTaskletStepBuilder<SimpleStepBuilder<I,O>>`
      Parameters:
        `stream` - the stream to register
      Returns:
        this for fluent chaining

    - #### faultTolerant

          public FaultTolerantStepBuilder<I,O> faultTolerant()

      Override parent method to prevent creation of a new FaultTolerantStepBuilder
      Overrides:
        `faultTolerant` in class `SimpleStepBuilder<I,O>`

    - #### createChunkProvider

          protected ChunkProvider<I> createChunkProvider()

    - #### createChunkProcessor

          protected ChunkProcessor<I> createChunkProcessor()

    - #### detectStreamInReader

          protected void detectStreamInReader()

    - #### getRollbackClassifier

          protected org.springframework.classify.Classifier<java.lang.Throwable,java.lang.Boolean> getRollbackClassifier()

      Convenience method to get an exception classifier based on the provided transaction attributes.
      Returns:
        an exception classifier: maps to true if an exception should cause rollback

    - #### createSkipPolicy

          protected SkipPolicy createSkipPolicy()

    - #### createRetryOperations

          protected BatchRetryTemplate createRetryOperations()

      Returns:
        fully configured retry template for item processing phase.

    - #### getChunkMonitor

          protected ChunkMonitor getChunkMonitor()

    - #### getSkipListeners

          protected java.util.Set<SkipListener<? super I,? super O>> getSkipListeners()

    - #### getJsrRetryListeners

          protected java.util.Set<RetryListener> getJsrRetryListeners()

    - #### getFatalExceptionAwareProxy

          protected SkipPolicy getFatalExceptionAwareProxy(SkipPolicy skipPolicy)

      Wrap a `SkipPolicy` and make it consistent with known fatal exceptions.
      Parameters:
        `skipPolicy` - an existing skip policy
      Returns:
        a skip policy that will not skip fatal exceptions