OPEN - issue BATCH-378: RepeatListener is confusing and too generic to use for 'intercepting' a step
http://jira.springframework.org/browse/BATCH-378 Add listener multicaster to ItemOrientedStep
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package org.springframework.batch.item.stream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -24,20 +25,28 @@ import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.exception.StreamException;
|
||||
|
||||
/**
|
||||
* Simple {@link StreamManager} that tries to resolve conflicts between key
|
||||
* names by using the class name of a stream to prefix property keys.
|
||||
* Simple {@link ItemStream} that delegates to a list of other streams.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class SimpleStreamManager implements ItemStream {
|
||||
public class CompositeItemStream implements ItemStream {
|
||||
|
||||
private List streams = new ArrayList();
|
||||
|
||||
/**
|
||||
* Public setter for the listeners.
|
||||
*
|
||||
* @param listeners
|
||||
*/
|
||||
public void setStreams(ItemStream[] listeners) {
|
||||
this.streams = Arrays.asList(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public SimpleStreamManager() {
|
||||
public CompositeItemStream() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -82,7 +91,6 @@ public class SimpleStreamManager implements ItemStream {
|
||||
ItemStream itemStream = (ItemStream) it.next();
|
||||
itemStream.close(executionContext);
|
||||
}
|
||||
streams.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.List;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.exception.StreamException;
|
||||
|
||||
/**
|
||||
@@ -29,13 +30,13 @@ import org.springframework.batch.item.exception.StreamException;
|
||||
*/
|
||||
public class SimpleStreamManagerTests extends TestCase {
|
||||
|
||||
private SimpleStreamManager manager = new SimpleStreamManager();
|
||||
private CompositeItemStream manager = new CompositeItemStream();
|
||||
|
||||
private List list = new ArrayList();
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#commit(org.springframework.transaction.TransactionStatus)}.
|
||||
* {@link org.springframework.batch.item.stream.CompositeItemStream#commit(org.springframework.transaction.TransactionStatus)}.
|
||||
*/
|
||||
public void testRegisterAndOpen() {
|
||||
ItemStreamSupport stream = new ItemStreamSupport() {
|
||||
@@ -50,7 +51,7 @@ public class SimpleStreamManagerTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#commit(org.springframework.transaction.TransactionStatus)}.
|
||||
* {@link org.springframework.batch.item.stream.CompositeItemStream#commit(org.springframework.transaction.TransactionStatus)}.
|
||||
*/
|
||||
public void testRegisterTwice() {
|
||||
ItemStreamSupport stream = new ItemStreamSupport() {
|
||||
@@ -66,7 +67,7 @@ public class SimpleStreamManagerTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#commit(org.springframework.transaction.TransactionStatus)}.
|
||||
* {@link org.springframework.batch.item.stream.CompositeItemStream#commit(org.springframework.transaction.TransactionStatus)}.
|
||||
*/
|
||||
public void testMark() {
|
||||
manager.register(new ItemStreamSupport() {
|
||||
@@ -80,7 +81,7 @@ public class SimpleStreamManagerTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#commit(org.springframework.transaction.TransactionStatus)}.
|
||||
* {@link org.springframework.batch.item.stream.CompositeItemStream#commit(org.springframework.transaction.TransactionStatus)}.
|
||||
*/
|
||||
public void testClose() {
|
||||
manager.register(new ItemStreamSupport() {
|
||||
@@ -94,18 +95,18 @@ public class SimpleStreamManagerTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.stream.SimpleStreamManager#commit(org.springframework.transaction.TransactionStatus)}.
|
||||
* {@link org.springframework.batch.item.stream.CompositeItemStream#commit(org.springframework.transaction.TransactionStatus)}.
|
||||
*/
|
||||
public void testCloseUnregisters() {
|
||||
manager.register(new ItemStreamSupport() {
|
||||
public void testCloseDoesNotUnregister() {
|
||||
manager.setStreams(new ItemStream[] { new ItemStreamSupport() {
|
||||
public void open(ExecutionContext executionContext) throws StreamException {
|
||||
list.add("bar");
|
||||
}
|
||||
});
|
||||
} });
|
||||
manager.open(null);
|
||||
manager.close(null);
|
||||
manager.open(null);
|
||||
assertEquals(1, list.size());
|
||||
assertEquals(2, list.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user