Class SimpleRetryExceptionHandler
- java.lang.Object
- org.springframework.retry.listener.RetryListenerSupport
- org.springframework.batch.core.step.item.SimpleRetryExceptionHandler
- All Implemented Interfaces:
ExceptionHandler
,org.springframework.retry.RetryListener
public class SimpleRetryExceptionHandler extends org.springframework.retry.listener.RetryListenerSupport implements ExceptionHandler
AnExceptionHandler
that is aware of the retry context so that it can distinguish between a fatal exception and one that can be retried. Delegates the actual exception handling to anotherExceptionHandler
.- Author:
- Dave Syer
Constructor Summary
Constructors Constructor Description SimpleRetryExceptionHandler(org.springframework.retry.RetryPolicy retryPolicy, ExceptionHandler exceptionHandler, java.util.Collection<java.lang.Class<? extends java.lang.Throwable>> fatalExceptionClasses)
Create an exception handler from its mandatory properties.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T,E extends java.lang.Throwable>
voidclose(org.springframework.retry.RetryContext context, org.springframework.retry.RetryCallback<T,E> callback, java.lang.Throwable throwable)
If retry is exhausted set up some state in the context that can be used to signal that the exception should be handled.void
handleException(RepeatContext context, java.lang.Throwable throwable)
Check if the exception is going to be retried, and veto the handling if it is.
Constructor Detail
SimpleRetryExceptionHandler
public SimpleRetryExceptionHandler(org.springframework.retry.RetryPolicy retryPolicy, ExceptionHandler exceptionHandler, java.util.Collection<java.lang.Class<? extends java.lang.Throwable>> fatalExceptionClasses)
Create an exception handler from its mandatory properties.- Parameters:
retryPolicy
- the retry policy that will be under effect when an exception is encounteredexceptionHandler
- the delegate to use if an exception actually needs to be handledfatalExceptionClasses
- exceptions
Method Detail
handleException
public void handleException(RepeatContext context, java.lang.Throwable throwable) throws java.lang.Throwable
Check if the exception is going to be retried, and veto the handling if it is. If retry is exhausted or the exception is on the fatal list, then handle using the delegate.- 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:
ExceptionHandler.handleException(org.springframework.batch.repeat.RepeatContext, java.lang.Throwable)
close
public <T,E extends java.lang.Throwable> void close(org.springframework.retry.RetryContext context, org.springframework.retry.RetryCallback<T,E> callback, java.lang.Throwable throwable)
If retry is exhausted set up some state in the context that can be used to signal that the exception should be handled.- Specified by:
close
in interfaceorg.springframework.retry.RetryListener
- Overrides:
close
in classorg.springframework.retry.listener.RetryListenerSupport
- See Also:
RetryListener.close(org.springframework.retry.RetryContext, org.springframework.retry.RetryCallback, java.lang.Throwable)