BATCH-919: reuse ChunkProcessor in integration

This commit is contained in:
dsyer
2008-12-30 16:32:29 +00:00
parent 7d7480578d
commit a6479602e2
18 changed files with 166 additions and 200 deletions

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.batch.core;
import java.io.Serializable;
/**
* Represents a contribution to a {@link StepExecution}, buffering changes until
* they can be applied at a chunk boundary.
@@ -22,7 +24,7 @@ package org.springframework.batch.core;
* @author Dave Syer
*
*/
public class StepContribution {
public class StepContribution implements Serializable {
private volatile int readCount = 0;

View File

@@ -1,6 +1,7 @@
package org.springframework.batch.core.step.item;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -15,7 +16,7 @@ import java.util.List;
* @author Dave Syer
*
*/
class Chunk<W> implements Iterable<W> {
public class Chunk<W> implements Iterable<W> {
private List<W> items = new ArrayList<W>();
@@ -30,8 +31,12 @@ class Chunk<W> implements Iterable<W> {
public Chunk() {
this(null,null);
}
public Chunk(Collection<? extends W> items) {
this(items,null);
}
public Chunk(List<W> items, List<SkipWrapper<W>> skips) {
public Chunk(Collection<? extends W> items, List<SkipWrapper<W>> skips) {
super();
if (items!=null) {
this.items = new ArrayList<W>(items);

View File

@@ -8,20 +8,55 @@ import org.springframework.batch.core.listener.MulticasterBatchListener;
import org.springframework.batch.core.step.skip.SkipListenerFailedException;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
public class SimpleChunkProcessor<I, O> implements ChunkProcessor<I> {
public class SimpleChunkProcessor<I, O> implements ChunkProcessor<I>, InitializingBean {
private final ItemProcessor<? super I, ? extends O> itemProcessor;
private ItemProcessor<? super I, ? extends O> itemProcessor;
private final ItemWriter<? super O> itemWriter;
private ItemWriter<? super O> itemWriter;
private final MulticasterBatchListener<I, O> listener = new MulticasterBatchListener<I, O>();
/**
* Default constructor for ease of configuration (both itemWriter and
* itemProcessor are mandatory).
*/
@SuppressWarnings("unused")
private SimpleChunkProcessor() {
this(null, null);
}
public SimpleChunkProcessor(ItemProcessor<? super I, ? extends O> itemProcessor, ItemWriter<? super O> itemWriter) {
this.itemProcessor = itemProcessor;
this.itemWriter = itemWriter;
}
/**
* @param itemProcessor the {@link ItemProcessor} to set
*/
public void setItemProcessor(ItemProcessor<? super I, ? extends O> itemProcessor) {
this.itemProcessor = itemProcessor;
}
/**
* @param itemWriter the {@link ItemWriter} to set
*/
public void setItemWriter(ItemWriter<? super O> itemWriter) {
this.itemWriter = itemWriter;
}
/**
* Check mandatory properties.
*
* @see InitializingBean#afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception {
Assert.notNull(itemWriter, "ItemWriter must be set");
Assert.notNull(itemProcessor, "ItemProcessor must be set");
}
/**
* Register some {@link StepListener}s with the handler. Each will get the
* callbacks in the order specified at the correct stage.