public class SimpleChunkProcessor<I,O> extends java.lang.Object implements ChunkProcessor<I>, org.springframework.beans.factory.InitializingBean
ChunkProcessor
interface that handles
basic item writing and processing. Any exceptions encountered will be
rethrown.ChunkOrientedTasklet
Constructor and Description |
---|
SimpleChunkProcessor(ItemProcessor<? super I,? extends O> itemProcessor,
ItemWriter<? super O> itemWriter) |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Check mandatory properties.
|
protected void |
doAfterWrite(java.util.List<O> items)
Call the listener's after write method.
|
protected void |
doOnWriteError(java.lang.Exception e,
java.util.List<O> items) |
protected O |
doProcess(I item) |
protected void |
doWrite(java.util.List<O> items)
Surrounds the actual write call with listener callbacks.
|
protected Chunk<O> |
getAdjustedOutputs(Chunk<I> inputs,
Chunk<O> outputs)
Extension point for subclasses that want to adjust the outputs based on
additional saved data in the inputs.
|
protected int |
getFilterCount(Chunk<I> inputs,
Chunk<O> outputs)
Extension point for subclasses to calculate the filter count.
|
protected MulticasterBatchListener<I,O> |
getListener() |
protected void |
initializeUserData(Chunk<I> inputs)
Extension point for subclasses to allow them to memorise the contents of
the inputs, in case they are needed for accounting purposes later.
|
protected boolean |
isComplete(Chunk<I> inputs)
Extension point for subclasses that want to store additional data in the
inputs.
|
void |
process(StepContribution contribution,
Chunk<I> inputs) |
void |
registerListener(StepListener listener)
Register a listener for callbacks at the appropriate stages in a process.
|
void |
setItemProcessor(ItemProcessor<? super I,? extends O> itemProcessor) |
void |
setItemWriter(ItemWriter<? super O> itemWriter) |
void |
setListeners(java.util.List<? extends StepListener> listeners)
Register some
StepListener s with the handler. |
protected Chunk<O> |
transform(StepContribution contribution,
Chunk<I> inputs) |
protected void |
write(StepContribution contribution,
Chunk<I> inputs,
Chunk<O> outputs)
Simple implementation delegates to the
doWrite(List) method and
increments the write count in the contribution. |
protected void |
writeItems(java.util.List<O> items) |
public SimpleChunkProcessor(ItemProcessor<? super I,? extends O> itemProcessor, ItemWriter<? super O> itemWriter)
public void setItemProcessor(ItemProcessor<? super I,? extends O> itemProcessor)
itemProcessor
- the ItemProcessor
to setpublic void setItemWriter(ItemWriter<? super O> itemWriter)
itemWriter
- the ItemWriter
to setpublic void afterPropertiesSet() throws java.lang.Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
java.lang.Exception
InitializingBean.afterPropertiesSet()
public void setListeners(java.util.List<? extends StepListener> listeners)
StepListener
s with the handler. Each will get the
callbacks in the order specified at the correct stage.listeners
- public void registerListener(StepListener listener)
listener
- a StepListener
protected MulticasterBatchListener<I,O> getListener()
protected final O doProcess(I item) throws java.lang.Exception
item
- the input itemjava.lang.Exception
protected final void doWrite(java.util.List<O> items) throws java.lang.Exception
items
- java.lang.Exception
protected final void doAfterWrite(java.util.List<O> items)
items
- protected final void doOnWriteError(java.lang.Exception e, java.util.List<O> items)
protected void writeItems(java.util.List<O> items) throws java.lang.Exception
java.lang.Exception
public final void process(StepContribution contribution, Chunk<I> inputs) throws java.lang.Exception
process
in interface ChunkProcessor<I>
java.lang.Exception
protected void initializeUserData(Chunk<I> inputs)
isComplete(Chunk)
, getFilterCount(Chunk, Chunk)
and
getAdjustedOutputs(Chunk, Chunk)
might also need to be, to
ensure that the user data is handled consistently.inputs
- the inputs for the processprotected int getFilterCount(Chunk<I> inputs, Chunk<O> outputs)
inputs
- the inputs after transformationoutputs
- the outputs after transformationinitializeUserData(Chunk)
protected boolean isComplete(Chunk<I> inputs)
inputs
- the input chunkinitializeUserData(Chunk)
protected Chunk<O> getAdjustedOutputs(Chunk<I> inputs, Chunk<O> outputs)
inputs
- the inputs for the transformationoutputs
- the result of the transformationinitializeUserData(Chunk)
protected void write(StepContribution contribution, Chunk<I> inputs, Chunk<O> outputs) throws java.lang.Exception
doWrite(List)
method and
increments the write count in the contribution. Subclasses can handle
more complicated scenarios, e.g.with fault tolerance. If output items are
skipped they should be removed from the inputs as well.contribution
- the current step contributioninputs
- the inputs that gave rise to the outputsoutputs
- the outputs to writejava.lang.Exception
- if there is a problemprotected Chunk<O> transform(StepContribution contribution, Chunk<I> inputs) throws java.lang.Exception
java.lang.Exception