Class LimitCheckingItemSkipPolicy
- All Implemented Interfaces:
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
FlatFileParseException
s, 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
. A Classifier
is used to determine whether a particular exception
is skippable or not.
- Author:
- Ben Hale, Lucas Ward, Robert Kasanicky, Dave Syer, Dan Garrette, Mahmoud Ben Hassine
-
Constructor Summary
ConstructorDescriptionConvenience constructor that assumes all exception types are fatal.LimitCheckingItemSkipPolicy
(int skipLimit, Map<Class<? extends Throwable>, Boolean> skippableExceptions) LimitCheckingItemSkipPolicy
(int skipLimit, org.springframework.classify.Classifier<Throwable, Boolean> skippableExceptionClassifier) -
Method Summary
Modifier and TypeMethodDescriptionvoid
setSkipLimit
(long skipLimit) The absolute number of skips (of skippable exceptions) that can be tolerated before a failure.void
setSkippableExceptionClassifier
(org.springframework.classify.Classifier<Throwable, Boolean> skippableExceptionClassifier) The classifier that will be used to decide on skippability.void
setSkippableExceptionMap
(Map<Class<? extends Throwable>, Boolean> skippableExceptions) Set up the classifier through a convenient map from throwable class to boolean (true if skippable).boolean
shouldSkip
(Throwable t, long skipCount) Given the provided exception and skip count, determine whether or not processing should continue for the given exception.
-
Constructor Details
-
LimitCheckingItemSkipPolicy
public LimitCheckingItemSkipPolicy()Convenience constructor that assumes all exception types are fatal. -
LimitCheckingItemSkipPolicy
public LimitCheckingItemSkipPolicy(int skipLimit, Map<Class<? extends Throwable>, Boolean> skippableExceptions) - Parameters:
skipLimit
- the number of skippable exceptions that are allowed to be skippedskippableExceptions
- exception classes that can be skipped (non-critical)
-
LimitCheckingItemSkipPolicy
public LimitCheckingItemSkipPolicy(int skipLimit, org.springframework.classify.Classifier<Throwable, Boolean> skippableExceptionClassifier) - Parameters:
skipLimit
- the number of skippable exceptions that are allowed to be skippedskippableExceptionClassifier
- exception classifier for those that can be skipped (non-critical)
-
-
Method Details
-
setSkipLimit
public void setSkipLimit(long skipLimit) The absolute number of skips (of skippable exceptions) that can be tolerated before a failure.- Parameters:
skipLimit
- the skip limit to set
-
setSkippableExceptionClassifier
public void setSkippableExceptionClassifier(org.springframework.classify.Classifier<Throwable, Boolean> skippableExceptionClassifier) The classifier that will be used to decide on skippability. If an exception classifies as "true" then it is skippable, and otherwise not.- Parameters:
skippableExceptionClassifier
- the skippableExceptionClassifier to set
-
setSkippableExceptionMap
Set up the classifier through a convenient map from throwable class to boolean (true if skippable).- Parameters:
skippableExceptions
- the skippable exceptions to set
-
shouldSkip
Given the provided exception and skip count, determine whether or not processing should continue for the given exception. If the exception is not classified as skippable in the classifier, false will be returned. If the exception is classified as skippable andStepExecution
skipCount is greater than the skipLimit, then aSkipLimitExceededException
will be thrown.- Specified by:
shouldSkip
in interfaceSkipPolicy
- Parameters:
t
- exception encountered while processingskipCount
- currently running count of skips- Returns:
- true if processing should continue, false otherwise.
-