org.springframework.batch.core.step.builder
Class FaultTolerantStepBuilder<I,O>

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

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

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.StepBuilderHelper
logger
 
Constructor Summary
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
 FaultTolerantStepBuilder<I,O> backOffPolicy(org.springframework.retry.backoff.BackOffPolicy backOffPolicy)
          Provide a backoff policy to prevent items being retried immediately (e.g.
protected  SkipPolicy createSkipPolicy()
           
protected  Tasklet createTasklet()
          Create a new chunk oriented tasklet with reader, writer and processor as provided.
 FaultTolerantStepBuilder<I,O> keyGenerator(KeyGenerator keyGenerator)
          Sets the key generator for identifying retried items.
 FaultTolerantStepBuilder<I,O> listener(ChunkListener listener)
          Register a chunk 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(Class<? extends Throwable> type)
          Explicitly ask for an exception (and subclasses) to be excluded from retry.
 FaultTolerantStepBuilder<I,O> noRollback(Class<? extends Throwable> type)
          Mark this exception as ignorable during item read or processing operations.
 FaultTolerantStepBuilder<I,O> noSkip(Class<? extends 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).
 FaultTolerantStepBuilder<I,O> retry(Class<? extends 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(Class<? extends Throwable> type)
          Explicitly request certain exceptions (and subclasses) to be skipped.
 FaultTolerantStepBuilder<I,O> skipLimit(int skipLimit)
          Sets the maximium 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
build, chunk, chunk, chunkOperations, createChunkOperations, faultTolerant, getChunkSize, getItemListeners, getProcessor, getReader, getWriter, isReaderTransactionalQueue, listener, listener, listener, processor, reader, readerIsTransactionalQueue, writer
 
Methods inherited from class org.springframework.batch.core.step.builder.AbstractTaskletStepBuilder
concurrent, exceptionHandler, getExceptionHandler, getStepOperations, 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

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 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 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 maximium 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(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.

Parameters:
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 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

createSkipPolicy

protected SkipPolicy createSkipPolicy()


Copyright © 2013 SpringSource. All Rights Reserved.