Merge pull request #62 from mminella/BATCH-1780

Batch-1780
This commit is contained in:
Michael Minella
2012-10-26 06:16:42 -07:00
5 changed files with 36 additions and 49 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@ import org.springframework.batch.item.ItemStream;
/**
* @author Dave Syer
*
* @author Michael Minella
*/
public class MulticasterBatchListener<T, S> implements StepExecutionListener, ChunkListener, ItemReadListener<T>,
ItemProcessListener<T, S>, ItemWriteListener<S>, SkipListener<T, S> {
@@ -57,7 +57,7 @@ public class MulticasterBatchListener<T, S> implements StepExecutionListener, Ch
/**
* Register each of the objects as listeners. Once registered, calls to the
* {@link MulticasterBatchListener} broadcast to the individual listeners.
*
*
* @param listeners listener objects of types known to the multicaster.
*/
public void setListeners(List<? extends StepListener> listeners) {
@@ -169,7 +169,7 @@ public class MulticasterBatchListener<T, S> implements StepExecutionListener, Ch
}
/**
*
*
* @see org.springframework.batch.core.listener.CompositeChunkListener#afterChunk()
*/
public void afterChunk() {
@@ -182,7 +182,7 @@ public class MulticasterBatchListener<T, S> implements StepExecutionListener, Ch
}
/**
*
*
* @see org.springframework.batch.core.listener.CompositeChunkListener#beforeChunk()
*/
public void beforeChunk() {
@@ -208,7 +208,7 @@ public class MulticasterBatchListener<T, S> implements StepExecutionListener, Ch
}
/**
*
*
* @see org.springframework.batch.core.listener.CompositeItemReadListener#beforeRead()
*/
public void beforeRead() {
@@ -229,12 +229,12 @@ public class MulticasterBatchListener<T, S> implements StepExecutionListener, Ch
itemReadListener.onReadError(ex);
}
catch (RuntimeException e) {
throw new StepListenerFailedException("Error in onReadError.", ex, e);
throw new StepListenerFailedException("Error in onReadError.", e);
}
}
/**
*
*
* @see ItemWriteListener#afterWrite(List)
*/
public void afterWrite(List<? extends S> items) {
@@ -269,7 +269,7 @@ public class MulticasterBatchListener<T, S> implements StepExecutionListener, Ch
itemWriteListener.onWriteError(ex, items);
}
catch (RuntimeException e) {
throw new StepListenerFailedException("Error in onWriteError.", ex, e);
throw new StepListenerFailedException("Error in onWriteError.", e);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,8 +18,9 @@ package org.springframework.batch.core.listener;
/**
* Exception to indicate a problem in a step listener.
*
*
* @author Dave Syer
* @author Michael Minella
*
*/
public class StepListenerFailedException extends RuntimeException {
@@ -31,14 +32,4 @@ public class StepListenerFailedException extends RuntimeException {
public StepListenerFailedException(String message, Throwable t) {
super(message, t);
}
/**
* @param message describes the error to the user
* @param ex the exception that was thrown by a listener
* @param e the exception that caused the skip
*/
public StepListenerFailedException(String message, Throwable ex, RuntimeException e) {
super(message + "\n" + e.getClass().getName() + ": " + e.getMessage(), ex);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,8 +32,9 @@ import org.springframework.batch.repeat.RepeatStatus;
/**
* Simple implementation of the ChunkProvider interface that does basic chunk
* providing from an {@link ItemReader}.
*
*
* @author Dave Syer
* @author Michael Minella
* @see ChunkOrientedTasklet
*/
public class SimpleChunkProvider<I> implements ChunkProvider<I> {
@@ -54,7 +55,7 @@ public class SimpleChunkProvider<I> implements ChunkProvider<I> {
/**
* Register some {@link StepListener}s with the handler. Each will get the
* callbacks in the order specified at the correct stage.
*
*
* @param listeners
*/
public void setListeners(List<? extends StepListener> listeners) {
@@ -65,7 +66,7 @@ public class SimpleChunkProvider<I> implements ChunkProvider<I> {
/**
* Register a listener for callbacks at the appropriate stages in a process.
*
*
* @param listener a {@link StepListener}
*/
public void registerListener(StepListener listener) {
@@ -94,6 +95,7 @@ public class SimpleChunkProvider<I> implements ChunkProvider<I> {
return item;
}
catch (Exception e) {
logger.debug(e.getMessage() + " : " + e.getClass().getName());
listener.onReadError(e);
throw e;
}
@@ -136,14 +138,14 @@ public class SimpleChunkProvider<I> implements ChunkProvider<I> {
/**
* Delegates to {@link #doRead()}. Subclasses can add additional behaviour
* (e.g. exception handling).
*
*
* @param contribution the current step execution contribution
* @param chunk the current chunk
* @return a new item for processing
*
*
* @throws SkipOverflowException if specifically the chunk is accumulating
* too much data (e.g. skips) and it wants to force a commit.
*
*
* @throws Exception if there is a generic issue
*/
protected I read(StepContribution contribution, Chunk<I> chunk) throws SkipOverflowException, Exception {

View File

@@ -28,7 +28,7 @@ import org.springframework.batch.core.StepExecution;
/**
* @author Dave Syer
*
*
*/
public class MulticasterBatchListenerTests {
@@ -276,7 +276,7 @@ public class MulticasterBatchListenerTests {
catch (StepListenerFailedException e) {
// expected
String message = e.getCause().getMessage();
assertEquals("Wrong message: " + message, "foo", message);
assertEquals("Wrong message: " + message, "listener error", message);
}
assertEquals(1, count);
}
@@ -369,7 +369,7 @@ public class MulticasterBatchListenerTests {
catch (StepListenerFailedException e) {
// expected
String message = e.getCause().getMessage();
assertEquals("Wrong message: " + message, "foo", message);
assertEquals("Wrong message: " + message, "listener error", message);
}
assertEquals(1, count);
}
@@ -508,7 +508,7 @@ public class MulticasterBatchListenerTests {
/**
* @author Dave Syer
*
*
*/
private final class CountingStepListenerSupport extends StepListenerSupport<Integer, String> {
@Override
@@ -522,7 +522,7 @@ public class MulticasterBatchListenerTests {
/*
* (non-Javadoc)
*
*
* @see
* org.springframework.batch.core.listener.StepListenerSupport#afterChunk
* ()
@@ -538,7 +538,7 @@ public class MulticasterBatchListenerTests {
/*
* (non-Javadoc)
*
*
* @see
* org.springframework.batch.core.listener.StepListenerSupport#afterRead
* (java.lang.Object)
@@ -554,7 +554,7 @@ public class MulticasterBatchListenerTests {
/*
* (non-Javadoc)
*
*
* @see
* org.springframework.batch.core.listener.StepListenerSupport#afterStep
* (org.springframework.batch.core.StepExecution)
@@ -570,7 +570,7 @@ public class MulticasterBatchListenerTests {
/*
* (non-Javadoc)
*
*
* @see
* org.springframework.batch.core.listener.StepListenerSupport#beforeChunk
* ()
@@ -586,7 +586,7 @@ public class MulticasterBatchListenerTests {
/*
* (non-Javadoc)
*
*
* @see
* org.springframework.batch.core.listener.StepListenerSupport#beforeRead
* ()
@@ -602,7 +602,7 @@ public class MulticasterBatchListenerTests {
/*
* (non-Javadoc)
*
*
* @see
* org.springframework.batch.core.listener.StepListenerSupport#beforeStep
* (org.springframework.batch.core.StepExecution)
@@ -618,7 +618,7 @@ public class MulticasterBatchListenerTests {
/*
* (non-Javadoc)
*
*
* @see
* org.springframework.batch.core.listener.StepListenerSupport#afterWrite
* (java.util.List)
@@ -634,7 +634,7 @@ public class MulticasterBatchListenerTests {
/*
* (non-Javadoc)
*
*
* @see
* org.springframework.batch.core.listener.StepListenerSupport#beforeWrite
* (java.util.List)
@@ -650,7 +650,7 @@ public class MulticasterBatchListenerTests {
/*
* (non-Javadoc)
*
*
* @see
* org.springframework.batch.core.listener.StepListenerSupport#onWriteError
* (java.lang.Exception, java.util.List)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ import org.junit.Test;
/**
* @author Dave Syer
* @author Michael Minella
*
*/
public class StepListenerFailedExceptionTests {
@@ -32,11 +33,4 @@ public class StepListenerFailedExceptionTests {
Exception exception = new StepListenerFailedException("foo", new IllegalStateException("bar"));
assertEquals("foo", exception.getMessage().substring(0, 3));
}
@Test
public void testExceptionStringThrowableThrowable() throws Exception {
Exception exception = new StepListenerFailedException("foo", new IllegalStateException(), new RuntimeException("bar"));
assertEquals("foo", exception.getMessage().substring(0, 3));
}
}