RESOLVED - issue BATCH-485: SkippableExceptionClasses should be inverted

http://jira.springframework.org/browse/BATCH-485

SkipLimitStepFactoryBean now declares setter for fatal exceptions that are never skipped and immediately rethrown by exception handlerRESOLVED - issue BATCH-485: SkippableExceptionClasses should be inverted 
http://jira.springframework.org/browse/BATCH-485

SkipLimitStepFactoryBean now declares setter for fatal exceptions that are never skipped and immediately rethrown by exception handler.
LimitCheckingItemSkipPolicy and SimpleLimitExceptionHandler were modified to recognize fatal exceptions.
This commit is contained in:
robokaso
2008-03-20 10:04:27 +00:00
parent 79967e173c
commit 4cc2e03fbd
5 changed files with 152 additions and 38 deletions

View File

@@ -22,23 +22,35 @@ import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.support.ExceptionClassifierSupport;
/**
* Simple implementation of exception handler which looks for one exception
* type. If it is found then a counter is incremented and the a limit is checked
* to determine if it has been exceeded and the Throwable should be re-thrown.
* Simple implementation of exception handler which looks for given exception
* types. If one of the types is found then a counter is incremented and the
* limit is checked to determine if it has been exceeded and the Throwable
* should be re-thrown. Also allows to specify list of 'fatal' exceptions that
* are never subject to counting, but are immediately re-thrown. The fatal list
* has higher priority so the two lists needn't be exclusive.
*
* @author Dave Syer
* @author Robert Kasanicky
*/
public class SimpleLimitExceptionHandler implements ExceptionHandler {
/**
* Name of exception classifier key for the nominated exception type.
* Name of exception classifier key for the nominated exception types.
*/
private static final String TX_INVALID = "TX_INVALID";
/**
* Name of exception classifier key for the fatal exception types (not
* counted, immediately rethrown).
*/
private static final String FATAL = "FATAL";
private RethrowOnThresholdExceptionHandler delegate = new RethrowOnThresholdExceptionHandler();
private Class[] exceptionClasses = new Class[] { Exception.class };
private Class[] fatalExceptionClasses = new Class[] { Error.class };
/**
* Flag to indicate the the exception counters should be shared between
* sibling contexts in a nested batch (i.e. inner loop). Default is false.
@@ -68,6 +80,11 @@ public class SimpleLimitExceptionHandler implements ExceptionHandler {
super();
delegate.setExceptionClassifier(new ExceptionClassifierSupport() {
public Object classify(Throwable throwable) {
for (int i = 0; i < fatalExceptionClasses.length; i++) {
if (fatalExceptionClasses[i].isAssignableFrom(throwable.getClass())) {
return FATAL;
}
}
for (int i = 0; i < exceptionClasses.length; i++) {
if (exceptionClasses[i].isAssignableFrom(throwable.getClass())) {
return TX_INVALID;
@@ -103,20 +120,30 @@ public class SimpleLimitExceptionHandler implements ExceptionHandler {
{
put(ExceptionClassifierSupport.DEFAULT, new Integer(0));
put(TX_INVALID, new Integer(limit));
put(FATAL, new Integer(0));
}
});
}
/**
* Setter for the Throwable exceptionClasses that this handler counts. Defaults to
* {@link Exception}. If more exceptionClasses are specified handler uses single
* counter that is incremented when one of the recognized exception
* exceptionClasses is handled.
*
* @param type
* Setter for the Throwable exceptionClasses that this handler counts.
* Defaults to {@link Exception}. If more exceptionClasses are specified
* handler uses single counter that is incremented when one of the
* recognized exception exceptionClasses is handled.
*/
public void setExceptionClasses(Class[] classes) {
this.exceptionClasses = classes;
}
/**
* Setter for the Throwable exceptionClasses that shouldn't be counted, but
* rethrown immediately. This list has higher priority than
* {@link #exceptionClasses}.
*
* @param fatalExceptionClasses defaults to {@link Error}
*/
public void setFatalExceptionClasses(Class[] fatalExceptionClasses) {
this.fatalExceptionClasses = fatalExceptionClasses;
}
}