org.springframework.batch.repeat.exception
Class RethrowOnThresholdExceptionHandler

java.lang.Object
  extended by org.springframework.batch.repeat.exception.RethrowOnThresholdExceptionHandler
All Implemented Interfaces:
ExceptionHandler

public class RethrowOnThresholdExceptionHandler
extends Object
implements ExceptionHandler

Implementation of ExceptionHandler that rethrows when exceptions of a given type reach a threshold. Requires an Classifier that maps exception types to unique keys, and also a map from those keys to threshold values (Integer type).

Author:
Dave Syer

Field Summary
protected  Log logger
           
protected static org.springframework.batch.repeat.exception.RethrowOnThresholdExceptionHandler.IntegerHolder ZERO
           
 
Constructor Summary
RethrowOnThresholdExceptionHandler()
          Set up the exception handler.
 
Method Summary
 void handleException(RepeatContext context, Throwable throwable)
          Classify the throwables and decide whether to re-throw based on the result.
 void setThresholds(Map<Class<? extends Throwable>,Integer> thresholds)
          A map from exception classes to a threshold value of type Integer.
 void setUseParent(boolean useParent)
          Flag to indicate the the exception counters should be shared between sibling contexts in a nested batch.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZERO

protected static final org.springframework.batch.repeat.exception.RethrowOnThresholdExceptionHandler.IntegerHolder ZERO

logger

protected final Log logger
Constructor Detail

RethrowOnThresholdExceptionHandler

public RethrowOnThresholdExceptionHandler()
Set up the exception handler. Creates a default exception handler and threshold that maps all exceptions to a threshold of 0 - all exceptions are rethrown by default.

Method Detail

setUseParent

public void setUseParent(boolean useParent)
Flag to indicate the the exception counters should be shared between sibling contexts in a nested batch. Default is false.

Parameters:
useParent - true if the parent context should be used to store the counters.

setThresholds

public void setThresholds(Map<Class<? extends Throwable>,Integer> thresholds)
A map from exception classes to a threshold value of type Integer.

Parameters:
thresholds - the threshold value map.

handleException

public void handleException(RepeatContext context,
                            Throwable throwable)
                     throws Throwable
Classify the throwables and decide whether to re-throw based on the result. The context is used to accumulate the number of exceptions of the same type according to the classifier.

Specified by:
handleException in interface ExceptionHandler
Parameters:
context - the current RepeatContext. Can be used to store state (via attributes), for example to count the number of occurrences of a particular exception type and implement a threshold policy.
throwable - an exception.
Throws:
Throwable
See Also:
ExceptionHandler.handleException(RepeatContext, Throwable)


Copyright © 2009 SpringSource. All Rights Reserved.