Class FaultTolerantStepBuilder<I,​O>

    • 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

      • registerStepListenerAsSkipListener

        protected void registerStepListenerAsSkipListener()
      • 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​(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
      • 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.
      • 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