org.springframework.batch.core.step.skip
Class LimitCheckingItemSkipPolicy

java.lang.Object
  extended by org.springframework.batch.core.step.skip.LimitCheckingItemSkipPolicy
All Implemented Interfaces:
SkipPolicy

public class LimitCheckingItemSkipPolicy
extends Object
implements SkipPolicy

SkipPolicy that determines whether or not reading should continue based upon how many items have been skipped. This is extremely useful behavior, as it allows you to skip records, but will throw a SkipLimitExceededException if a set limit has been exceeded. For example, it is generally advisable to skip FlatFileParseExceptions, however, if the vast majority of records are causing exceptions, the file is likely bad.

Furthermore, it is also likely that you only want to skip certain exceptions. FlatFileParseException is a good example of an exception you will likely want to skip, but a FileNotFoundException should cause immediate termination of the Step. Because it would be impossible for a general purpose policy to determine all the types of exceptions that should be skipped from those that shouldn't, two lists are passed in, with all of the exceptions that are 'fatal' and 'skippable'. The two lists are not enforced to be exclusive, they are prioritized instead - exceptions that are fatal will never be skipped, regardless whether the exception can also be classified as skippable.

Author:
Ben Hale, Lucas Ward, Robert Kasanicky, Dave Syer

Constructor Summary
LimitCheckingItemSkipPolicy(int skipLimit)
          Convenience constructor that assumes all exception types are skippable and none are fatal.
LimitCheckingItemSkipPolicy(int skipLimit, Classifier<Throwable,Boolean> skippableExceptionClassifier, Classifier<Throwable,Boolean> fatalExceptionClassifier)
           
LimitCheckingItemSkipPolicy(int skipLimit, Collection<Class<? extends Throwable>> skippableExceptions, Collection<Class<? extends Throwable>> fatalExceptions)
           
 
Method Summary
 boolean shouldSkip(Throwable t, int skipCount)
          Given the provided exception and skip count, determine whether or not processing should continue for the given exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LimitCheckingItemSkipPolicy

public LimitCheckingItemSkipPolicy(int skipLimit)
Convenience constructor that assumes all exception types are skippable and none are fatal.

Parameters:
skipLimit - the number of exceptions allowed to skip

LimitCheckingItemSkipPolicy

public LimitCheckingItemSkipPolicy(int skipLimit,
                                   Collection<Class<? extends Throwable>> skippableExceptions,
                                   Collection<Class<? extends Throwable>> fatalExceptions)
Parameters:
skipLimit - the number of skippable exceptions that are allowed to be skipped
skippableExceptions - exception classes that can be skipped (non-critical)
fatalExceptions - exception classes that should never be skipped

LimitCheckingItemSkipPolicy

public LimitCheckingItemSkipPolicy(int skipLimit,
                                   Classifier<Throwable,Boolean> skippableExceptionClassifier,
                                   Classifier<Throwable,Boolean> fatalExceptionClassifier)
Parameters:
skipLimit - the number of skippable exceptions that are allowed to be skipped
skippableExceptionClassifier - exception classifier for those that can be skipped (non-critical)
fatalExceptionClassifier - exception classifier for classes that should never be skipped
Method Detail

shouldSkip

public boolean shouldSkip(Throwable t,
                          int skipCount)
Given the provided exception and skip count, determine whether or not processing should continue for the given exception. If the exception is not within the list of 'skippable exceptions' or belongs to the list of 'fatal exceptions', false will be returned. If the exception is within the skippable list (and not in the fatal list), and StepExecution skipCount is greater than the skipLimit, then a SkipLimitExceededException will be thrown.

Specified by:
shouldSkip in interface SkipPolicy
Parameters:
t - exception encountered while reading
skipCount - currently running count of skips
Returns:
true if processing should continue, false otherwise.


Copyright © 2009 SpringSource. All Rights Reserved.