OPEN - issue BATCH-753: Listener exception handling
Add SkipListenerFailedException to write skip listener call
This commit is contained in:
@@ -244,23 +244,28 @@ public class SkipLimitStepFactoryBean<T> extends SimpleStepFactoryBean<T> {
|
||||
|
||||
List<Class<?>> exceptions = new ArrayList<Class<?>>(Arrays.asList(skippableExceptionClasses));
|
||||
ItemSkipPolicy readSkipPolicy = new LimitCheckingItemSkipPolicy(skipLimit, exceptions,
|
||||
new ArrayList<Class<?>>(){{
|
||||
for (Class<?> exceptionClass : fatalExceptionClasses) {
|
||||
add(exceptionClass);
|
||||
new ArrayList<Class<?>>() {
|
||||
{
|
||||
for (Class<?> exceptionClass : fatalExceptionClasses) {
|
||||
add(exceptionClass);
|
||||
}
|
||||
}
|
||||
}});
|
||||
exceptions.addAll(
|
||||
new ArrayList<Class<?>>(){{
|
||||
for (Class<?> exceptionClass : retryableExceptionClasses) {
|
||||
add(exceptionClass);
|
||||
}
|
||||
}});
|
||||
});
|
||||
exceptions.addAll(new ArrayList<Class<?>>() {
|
||||
{
|
||||
for (Class<?> exceptionClass : retryableExceptionClasses) {
|
||||
add(exceptionClass);
|
||||
}
|
||||
}
|
||||
});
|
||||
ItemSkipPolicy writeSkipPolicy = new LimitCheckingItemSkipPolicy(skipLimit, exceptions,
|
||||
new ArrayList<Class<?>>(){{
|
||||
for (Class<?> exceptionClass : fatalExceptionClasses) {
|
||||
add(exceptionClass);
|
||||
new ArrayList<Class<?>>() {
|
||||
{
|
||||
for (Class<?> exceptionClass : fatalExceptionClasses) {
|
||||
add(exceptionClass);
|
||||
}
|
||||
}
|
||||
}});
|
||||
});
|
||||
StatefulRetryItemHandler<T> itemHandler = new StatefulRetryItemHandler<T>(getItemReader(), getItemWriter(),
|
||||
retryTemplate, itemKeyGenerator, readSkipPolicy, writeSkipPolicy);
|
||||
itemHandler.setSkipListeners(BatchListenerFactoryHelper.getSkipListeners(getListeners()));
|
||||
@@ -335,8 +340,8 @@ public class SkipLimitStepFactoryBean<T> extends SimpleStepFactoryBean<T> {
|
||||
* @param listeners
|
||||
*/
|
||||
public void setSkipListeners(SkipListener[] listeners) {
|
||||
for (SkipListener listener1 : listeners) {
|
||||
registerSkipListener(listener1);
|
||||
for (SkipListener listener : listeners) {
|
||||
registerSkipListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,7 +421,12 @@ public class SkipLimitStepFactoryBean<T> extends SimpleStepFactoryBean<T> {
|
||||
public Object recover(RetryContext context) {
|
||||
Throwable t = context.getLastThrowable();
|
||||
if (writeSkipPolicy.shouldSkip(t, contribution.getStepSkipCount())) {
|
||||
listener.onSkipInWrite(item, t);
|
||||
try {
|
||||
listener.onSkipInWrite(item, t);
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
throw new SkipListenerFailedException("Fatal exception in SkipListener.", ex, t);
|
||||
}
|
||||
}
|
||||
contribution.incrementWriteSkipCount();
|
||||
return null;
|
||||
|
||||
@@ -31,10 +31,10 @@ public class SkipListenerFailedException extends UnexpectedJobExecutionException
|
||||
/**
|
||||
* @param message describes the error to the user
|
||||
* @param ex the exception that was thrown by a {@link SkipListener}
|
||||
* @param e the exception that caused the skip
|
||||
* @param t the exception that caused the skip
|
||||
*/
|
||||
public SkipListenerFailedException(String message, RuntimeException ex, Exception e) {
|
||||
super(message + "\n" + e.getClass().getName() + ": " + e.getMessage(), ex);
|
||||
public SkipListenerFailedException(String message, RuntimeException ex, Throwable t) {
|
||||
super(message + "\n" + t.getClass().getName() + ": " + t.getMessage(), ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user