Class FaultTolerantStepBuilder<I,O>

Direct Known Subclasses:
RemoteChunkingManagerStepBuilder

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, Ian Choi
  • Constructor Details

    • 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 Details

    • 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:
    • 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:
    • listener

      public FaultTolerantStepBuilder<I,O> listener(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(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 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. Default is 10.
      Returns:
      this for fluent chaining
    • noSkip

      public FaultTolerantStepBuilder<I,O> noSkip(Class<? extends 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(Class<? extends 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(Class<? extends 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(Class<? extends 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(Class<? extends 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 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<Throwable,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 Set<SkipListener<? super I,? super O>> getSkipListeners()
    • 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