Class JsrChunkProcessor<I,O>
- java.lang.Object
- org.springframework.batch.core.jsr.step.item.JsrChunkProcessor<I,O>
- Type Parameters:
I
- The input type for the stepO
- The output type for the step
- All Implemented Interfaces:
ChunkProcessor<I>
- Direct Known Subclasses:
JsrFaultTolerantChunkProcessor
public class JsrChunkProcessor<I,O> extends java.lang.Object implements ChunkProcessor<I>
ChunkProcessor
implementation that implements JSR-352's chunking pattern (read and process in a loop until the chunk is complete then write). This implementation is responsible for all three phases of chunk based processing (reading, processing and writing).- Author:
- Michael Minella
Constructor Summary
Constructors Constructor Description JsrChunkProcessor()
JsrChunkProcessor(ItemReader<? extends I> reader, ItemProcessor<? super I,? extends O> processor, ItemWriter<? super O> writer, RepeatOperations repeatTemplate)
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doPersist(StepContribution contribution, Chunk<O> chunk)
Implements writing and all related listener callsprotected I
doProvide(StepContribution contribution, Chunk<I> chunk)
Implements reading as well as any related listener calls required.protected O
doTransform(I item)
Implements processing and all related listener calls.protected MulticasterBatchListener<I,O>
getListener()
protected void
persist(StepContribution contribution, Chunk<O> chunk)
Responsible for the writing portion of the chunking loop.void
process(StepContribution contribution, Chunk<I> chunk)
Loops through reading (viaprovide(StepContribution, Chunk)
and processing (viatransform(StepContribution, Object)
) until the chunk is complete.protected I
provide(StepContribution contribution, Chunk<I> chunk)
Responsible for the reading portion of the chunking loop.void
registerListener(StepListener listener)
Register a listener for callbacks at the appropriate stages in a process.void
setListeners(java.util.List<? extends StepListener> listeners)
Register someStepListener
s with the handler.protected O
transform(StepContribution contribution, I item)
Responsible for the processing portion of the chunking loop.
Constructor Detail
JsrChunkProcessor
public JsrChunkProcessor()
JsrChunkProcessor
public JsrChunkProcessor(ItemReader<? extends I> reader, ItemProcessor<? super I,? extends O> processor, ItemWriter<? super O> writer, RepeatOperations repeatTemplate)
Method Detail
getListener
protected MulticasterBatchListener<I,O> getListener()
process
public void process(StepContribution contribution, Chunk<I> chunk) throws java.lang.Exception
Loops through reading (viaprovide(StepContribution, Chunk)
and processing (viatransform(StepContribution, Object)
) until the chunk is complete. Once the chunk is complete, the results are written (viapersist(StepContribution, Chunk)
.- Specified by:
process
in interfaceChunkProcessor<I>
- Parameters:
contribution
- aStepContribution
chunk
- aChunk
- Throws:
java.lang.Exception
- See Also:
ChunkProcessor.process(StepContribution, Chunk)
setListeners
public void setListeners(java.util.List<? extends StepListener> listeners)
Register someStepListener
s with the handler. Each will get the callbacks in the order specified at the correct stage.- Parameters:
listeners
- list of listeners to be used within this step
registerListener
public void registerListener(StepListener listener)
Register a listener for callbacks at the appropriate stages in a process.- Parameters:
listener
- aStepListener
provide
protected I provide(StepContribution contribution, Chunk<I> chunk) throws java.lang.Exception
Responsible for the reading portion of the chunking loop. In this implementation, delegates todoProvide(StepContribution, Chunk)
- Parameters:
contribution
- aStepContribution
chunk
- aChunk
- Returns:
- an item
- Throws:
java.lang.Exception
- thrown if error occurs during the reading portion of the chunking loop.
doProvide
protected final I doProvide(StepContribution contribution, Chunk<I> chunk) throws java.lang.Exception
Implements reading as well as any related listener calls required.- Parameters:
contribution
- aStepContribution
chunk
- aChunk
- Returns:
- an item
- Throws:
java.lang.Exception
- thrown if error occurs during reading or listener calls.
transform
protected O transform(StepContribution contribution, I item) throws java.lang.Exception
Responsible for the processing portion of the chunking loop. In this implementation, delegates to thedoTransform(Object)
if a processor is available (returns the item unmodified if it is not)- Parameters:
contribution
- aStepContribution
item
- an item- Returns:
- a processed item if a processor is present (the unmodified item if it is not)
- Throws:
java.lang.Exception
- thrown if error occurs during the processing portion of the chunking loop.
doTransform
protected final O doTransform(I item) throws java.lang.Exception
Implements processing and all related listener calls.- Parameters:
item
- the item to be processed- Returns:
- the processed item
- Throws:
java.lang.Exception
- thrown if error occurs during processing.
persist
protected void persist(StepContribution contribution, Chunk<O> chunk) throws java.lang.Exception
Responsible for the writing portion of the chunking loop. In this implementation, delegates to the {doPersist(StepContribution, Chunk)
.- Parameters:
contribution
- aStepContribution
chunk
- aChunk
- Throws:
java.lang.Exception
- thrown if error occurs during the writing portion of the chunking loop.
doPersist
protected final void doPersist(StepContribution contribution, Chunk<O> chunk) throws java.lang.Exception
Implements writing and all related listener calls- Parameters:
contribution
- aStepContribution
chunk
- aChunk
- Throws:
java.lang.Exception
- thrown if error occurs during the writing portion of the chunking loop.