Class SimpleLimitExceptionHandler
- java.lang.Object
- org.springframework.batch.repeat.exception.SimpleLimitExceptionHandler
- All Implemented Interfaces:
ExceptionHandler
,org.springframework.beans.factory.InitializingBean
public class SimpleLimitExceptionHandler extends java.lang.Object implements ExceptionHandler, org.springframework.beans.factory.InitializingBean
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, Robert Kasanicky
Constructor Summary
Constructors Constructor Description SimpleLimitExceptionHandler()
Default constructor for theSimpleLimitExceptionHandler
.SimpleLimitExceptionHandler(int limit)
Convenience constructor for theSimpleLimitExceptionHandler
to set the limit.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
Apply the provided properties to create a delegate handler.void
handleException(RepeatContext context, java.lang.Throwable throwable)
Rethrows only if the limit is breached for this context on the exception type specified.void
setExceptionClasses(java.util.Collection<java.lang.Class<? extends java.lang.Throwable>> classes)
Setter for the exception classes that this handler counts.void
setFatalExceptionClasses(java.util.Collection<java.lang.Class<? extends java.lang.Throwable>> fatalExceptionClasses)
Setter for the exception classes that shouldn't be counted, but rethrown immediately.void
setLimit(int limit)
The limit on the given exception type within a single context before it is rethrown.void
setUseParent(boolean useParent)
Flag to indicate the the exception counters should be shared between sibling contexts in a nested batch (i.e.
Constructor Detail
SimpleLimitExceptionHandler
public SimpleLimitExceptionHandler(int limit)
Convenience constructor for theSimpleLimitExceptionHandler
to set the limit.- Parameters:
limit
- the limit
SimpleLimitExceptionHandler
public SimpleLimitExceptionHandler()
Default constructor for theSimpleLimitExceptionHandler
.
Method Detail
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
Apply the provided properties to create a delegate handler.- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
java.lang.Exception
- See Also:
InitializingBean.afterPropertiesSet()
setUseParent
public void setUseParent(boolean useParent)
Flag to indicate the the exception counters should be shared between sibling contexts in a nested batch (i.e. inner loop). Default is false. Set this flag to true if you want to count exceptions for the whole (outer) loop in a typical container.- Parameters:
useParent
- true if the parent context should be used to store the counters.
handleException
public void handleException(RepeatContext context, java.lang.Throwable throwable) throws java.lang.Throwable
Rethrows only if the limit is breached for this context on the exception type specified.- Specified by:
handleException
in interfaceExceptionHandler
- Parameters:
context
- the currentRepeatContext
. 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:
java.lang.Throwable
- implementations are free to re-throw the exception- See Also:
setExceptionClasses(Collection)
,setLimit(int)
,ExceptionHandler.handleException(org.springframework.batch.repeat.RepeatContext, Throwable)
setLimit
public void setLimit(int limit)
The limit on the given exception type within a single context before it is rethrown.- Parameters:
limit
- the limit
setExceptionClasses
public void setExceptionClasses(java.util.Collection<java.lang.Class<? extends java.lang.Throwable>> classes)
Setter for the exception classes that this handler counts. Defaults toException
. If more exceptionClasses are specified handler uses single counter that is incremented when one of the recognized exception exceptionClasses is handled.- Parameters:
classes
- exceptionClasses
setFatalExceptionClasses
public void setFatalExceptionClasses(java.util.Collection<java.lang.Class<? extends java.lang.Throwable>> fatalExceptionClasses)
Setter for the exception classes that shouldn't be counted, but rethrown immediately. This list has higher priority thansetExceptionClasses(Collection)
.- Parameters:
fatalExceptionClasses
- defaults toError