org.springframework.batch.repeat.exception
Class LogOrRethrowExceptionHandler

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

public class LogOrRethrowExceptionHandler
extends Object
implements ExceptionHandler

Implementation of ExceptionHandler based on an ExceptionClassifier. The classifier determines whether to log the exception or rethrow it. The keys in the classifier must be the same as the static contants in this class.

Author:
Dave Syer

Field Summary
static String DEBUG
          Key for ExceptionClassifier signalling that the throwable should be logged at debug level.
static String ERROR
          Key for ExceptionClassifier signalling that the throwable should be logged at error level.
protected  org.apache.commons.logging.Log logger
           
static String RETHROW
          Key for ExceptionClassifier signalling that the throwable should be rethrown.
static String WARN
          Key for ExceptionClassifier signalling that the throwable should be logged at warn level.
 
Constructor Summary
LogOrRethrowExceptionHandler()
           
 
Method Summary
 void handleException(RepeatContext context, Throwable throwable)
          Classify the throwables and decide whether to rethrow based on the result.
 void setExceptionClassifier(ExceptionClassifier exceptionClassifier)
          Setter for the ExceptionClassifier used by this handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RETHROW

public static final String RETHROW
Key for ExceptionClassifier signalling that the throwable should be rethrown. If the throwable is not a RuntimeException it is wrapped in a RepeatException.

See Also:
Constant Field Values

DEBUG

public static final String DEBUG
Key for ExceptionClassifier signalling that the throwable should be logged at debug level.

See Also:
Constant Field Values

WARN

public static final String WARN
Key for ExceptionClassifier signalling that the throwable should be logged at warn level.

See Also:
Constant Field Values

ERROR

public static final String ERROR
Key for ExceptionClassifier signalling that the throwable should be logged at error level.

See Also:
Constant Field Values

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

LogOrRethrowExceptionHandler

public LogOrRethrowExceptionHandler()
Method Detail

setExceptionClassifier

public void setExceptionClassifier(ExceptionClassifier exceptionClassifier)
Setter for the ExceptionClassifier used by this handler. The default is to map all throwable instances to RETHROW.

Parameters:
exceptionClassifier -

handleException

public void handleException(RepeatContext context,
                            Throwable throwable)
                     throws Throwable
Classify the throwables and decide whether to rethrow based on the result. The context is not used.

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 © 2008 SpringSource. All Rights Reserved.