Class FaultTolerantStepBuilder<I,O>
java.lang.Object
org.springframework.batch.core.step.builder.StepBuilderHelper<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:
RemoteChunkingManagerStepBuilder
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
-
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
ModifierConstructorDescriptionprotected
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
Modifier and TypeMethodDescriptionbackOffPolicy
(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).build()
Build a step with the reader, writer, processor as provided.protected ChunkProcessor<I>
protected ChunkProvider<I>
protected BatchRetryTemplate
protected SkipPolicy
protected Tasklet
Create a new chunk oriented tasklet with reader, writer and processor as provided.protected void
Override parent method to prevent creation of a new FaultTolerantStepBuilderprotected ChunkMonitor
protected SkipPolicy
getFatalExceptionAwareProxy
(SkipPolicy skipPolicy) Wrap aSkipPolicy
and make it consistent with known fatal exceptions.Convenience method to get an exception classifier based on the provided transaction attributes.protected Set<SkipListener<? super I,
? super O>> keyGenerator
(KeyGenerator keyGenerator) Sets the key generator for identifying retried items.Registers objects using the annotation based listener configuration.listener
(ChunkListener listener) Register a chunk listener.listener
(SkipListener<? super I, ? super O> listener) Register a skip listener.listener
(org.springframework.retry.RetryListener listener) Register a retry listener.Explicitly ask for an exception (and subclasses) to be excluded from retry.noRollback
(Class<? extends Throwable> type) Mark this exception as ignorable during item read or processing operations.Explicitly prevent certain exceptions (and subclasses) from being skipped.Mark the item processor as non-transactional (default is the opposite).protected void
Explicitly ask for an exception (and subclasses) to be retried.retryContextCache
(org.springframework.retry.policy.RetryContextCache retryContextCache) Provide an explicit retry context cache.retryLimit
(int retryLimit) The maximum number of times to try a failed item.retryPolicy
(org.springframework.retry.RetryPolicy retryPolicy) Provide an explicit retry policy instead of using theretryLimit(int)
and retryable exceptions provided elsewhere.Explicitly request certain exceptions (and subclasses) to be skipped.skipLimit
(int skipLimit) Sets the maximum number of failed items to skip before the step fails.skipPolicy
(SkipPolicy skipPolicy) Provide an explicit policy for managing skips.stream
(ItemStream stream) Register a stream for callbacks that manage restart data.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, reader, readerIsTransactionalQueue, registerAsStreamsAndListeners, registerStepListenerAsItemListener, self, writer
Methods inherited from class org.springframework.batch.core.step.builder.AbstractTaskletStepBuilder
concurrent, exceptionHandler, getExceptionHandler, getStepOperations, getStreams, getTaskExecutor, getThrottleLimit, getTransactionAttribute, getTransactionManager, registerStepListenerAsChunkListener, stepOperations, taskExecutor, throttleLimit, transactionManager
Methods inherited from class org.springframework.batch.core.step.builder.StepBuilderHelper
allowStartIfComplete, enhance, getJobRepository, getName, isAllowStartIfComplete, listener, meterRegistry, observationConvention, observationRegistry, repository, startLimit
-
Constructor Details
-
FaultTolerantStepBuilder
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
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
Description copied from class:SimpleStepBuilder
Build a step with the reader, writer, processor as provided.- Overrides:
build
in classSimpleStepBuilder<I,
O> - Returns:
- a tasklet step fully configured and ready to execute
- See Also:
-
registerStepListenerAsSkipListener
protected void registerStepListenerAsSkipListener() -
createTasklet
Create a new chunk oriented tasklet with reader, writer and processor as provided.- Overrides:
createTasklet
in classSimpleStepBuilder<I,
O> - See Also:
-
listener
Registers objects using the annotation based listener configuration.- Overrides:
listener
in classSimpleStepBuilder<I,
O> - Parameters:
listener
- the object that has a method configured with listener annotation- Returns:
- this for fluent chaining
-
listener
Register a skip listener.- Parameters:
listener
- the listener to register- Returns:
- this for fluent chaining
-
listener
Description copied from class:AbstractTaskletStepBuilder
Register a chunk listener.- Overrides:
listener
in classAbstractTaskletStepBuilder<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 classAbstractTaskletStepBuilder<SimpleStepBuilder<I,
O>> - Parameters:
transactionAttribute
- a transaction attribute set- Returns:
- this for fluent chaining
-
listener
Register a retry listener.- Parameters:
listener
- the listener to register- Returns:
- this for fluent chaining
-
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
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 explicitretryPolicy
is set.- Parameters:
retryLimit
- the retry limit (default 0)- Returns:
- this for fluent chaining
-
retryPolicy
Provide an explicit retry policy instead of using theretryLimit(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 explicitretryPolicy
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
Sets the maximum number of failed items to skip before the step fails. Ignored if an explicitskipPolicy(SkipPolicy)
is provided.- Parameters:
skipLimit
- the skip limit to set. Default is 10.- Returns:
- this for fluent chaining
-
noSkip
Explicitly prevent certain exceptions (and subclasses) from being skipped.- Parameters:
type
- the non-skippable exception- Returns:
- this for fluent chaining
-
skip
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
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
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
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
Explicitly ask for an exception (and subclasses) to be retried.- Parameters:
type
- the exception to retry- Returns:
- this for fluent chaining
-
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
Description copied from class:AbstractTaskletStepBuilder
Register a stream for callbacks that manage restart data.- Overrides:
stream
in classAbstractTaskletStepBuilder<SimpleStepBuilder<I,
O>> - Parameters:
stream
- the stream to register- Returns:
- this for fluent chaining
-
faultTolerant
Override parent method to prevent creation of a new FaultTolerantStepBuilder- Overrides:
faultTolerant
in classSimpleStepBuilder<I,
O>
-
createChunkProvider
-
createChunkProcessor
-
detectStreamInReader
protected void detectStreamInReader() -
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
-
createRetryOperations
- Returns:
- fully configured retry template for item processing phase.
-
getChunkMonitor
-
getSkipListeners
-
getFatalExceptionAwareProxy
Wrap aSkipPolicy
and make it consistent with known fatal exceptions.- Parameters:
skipPolicy
- an existing skip policy- Returns:
- a skip policy that will not skip fatal exceptions
-