Class MulticasterBatchListener<T,S>
java.lang.Object
org.springframework.batch.core.listener.MulticasterBatchListener<T,S>
- All Implemented Interfaces:
ChunkListener,ItemProcessListener<T,,S> ItemReadListener<T>,ItemWriteListener<S>,SkipListener<T,,S> StepExecutionListener,StepListener
public class MulticasterBatchListener<T,S>
extends Object
implements StepExecutionListener, ChunkListener, ItemReadListener<T>, ItemProcessListener<T,S>, ItemWriteListener<S>, SkipListener<T,S>
- Author:
- Dave Syer, Michael Minella, Chris Schaefer, Mahmoud Ben Hassine
-
Field Summary
Fields inherited from interface org.springframework.batch.core.ChunkListener
ROLLBACK_EXCEPTION_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterChunk(ChunkContext context) Callback after the chunk is executed, outside the transaction.voidafterChunkError(ChunkContext context) Callback after a chunk has been marked for rollback.voidafterProcess(T item, S result) Called afterItemProcessor.process(Object)returns.voidCalled afterItemReader.read().afterStep(StepExecution stepExecution) Give a listener a chance to modify the exit status from a step.voidafterWrite(Chunk<? extends S> items) Called afterItemWriter.write(Chunk).voidbeforeChunk(ChunkContext context) Callback before the chunk is executed, but inside the transaction.voidbeforeProcess(T item) Called beforeItemProcessor.process(Object).voidCalled beforeItemReader.read()voidbeforeStep(StepExecution stepExecution) Initialize the state of the listener with theStepExecutionfrom the current scope.voidbeforeWrite(Chunk<? extends S> items) Called beforeItemWriter.write(Chunk)voidonProcessError(T item, Exception ex) Called if an exception was thrown fromItemProcessor.process(Object).voidonReadError(Exception ex) Called if an error occurs while trying to read.voidonSkipInProcess(T item, Throwable t) This item failed on processing with the given exception, and a skip was called for.voidCallback for a failure on read that is legal and, consequently, is not going to be re-thrown.voidonSkipInWrite(S item, Throwable t) This item failed on write with the given exception, and a skip was called for.voidonWriteError(Exception ex, Chunk<? extends S> items) Called if an error occurs while trying to write.voidregister(StepListener listener) Register the listener for callbacks on the appropriate interfaces implemented.voidsetListeners(List<? extends StepListener> listeners) Register each of the objects as listeners.
-
Constructor Details
-
MulticasterBatchListener
public MulticasterBatchListener()Initialize the listener instance.
-
-
Method Details
-
setListeners
Register each of the objects as listeners. Once registered, calls to theMulticasterBatchListenerbroadcast to the individual listeners.- Parameters:
listeners- listener objects of types known to the multicaster.
-
register
Register the listener for callbacks on the appropriate interfaces implemented. AnyStepListenercan be provided, or anItemStream. Other types will be ignored.- Parameters:
listener- theStepListenerinstance to be registered.
-
afterProcess
Description copied from interface:ItemProcessListenerCalled afterItemProcessor.process(Object)returns. If the processor returnsnull, this method is still called, with anullresult, allowing for notification of "filtered" items.- Specified by:
afterProcessin interfaceItemProcessListener<T,S> - Parameters:
item- to be processedresult- of processing- See Also:
-
beforeProcess
Description copied from interface:ItemProcessListenerCalled beforeItemProcessor.process(Object).- Specified by:
beforeProcessin interfaceItemProcessListener<T,S> - Parameters:
item- to be processed.- See Also:
-
onProcessError
Description copied from interface:ItemProcessListenerCalled if an exception was thrown fromItemProcessor.process(Object).- Specified by:
onProcessErrorin interfaceItemProcessListener<T,S> - Parameters:
item- attempted to be processedex- - exception thrown during processing.- See Also:
-
afterStep
Description copied from interface:StepExecutionListenerGive a listener a chance to modify the exit status from a step. The value returned is combined with the normal exit status by usingExitStatus.and(ExitStatus).Called after execution of the step's processing logic (whether successful or failed). Throwing an exception in this method has no effect, as it is only logged.
- Specified by:
afterStepin interfaceStepExecutionListener- Parameters:
stepExecution- aStepExecutioninstance.- Returns:
- an
ExitStatusto combine with the normal value. Returnnull(the default) to leave the old value unchanged. - See Also:
-
beforeStep
Description copied from interface:StepExecutionListenerInitialize the state of the listener with theStepExecutionfrom the current scope.- Specified by:
beforeStepin interfaceStepExecutionListener- Parameters:
stepExecution- instance ofStepExecution.- See Also:
-
afterChunk
Description copied from interface:ChunkListenerCallback after the chunk is executed, outside the transaction.- Specified by:
afterChunkin interfaceChunkListener- Parameters:
context- The currentChunkContext- See Also:
-
beforeChunk
Description copied from interface:ChunkListenerCallback before the chunk is executed, but inside the transaction.- Specified by:
beforeChunkin interfaceChunkListener- Parameters:
context- The currentChunkContext- See Also:
-
afterRead
Description copied from interface:ItemReadListenerCalled afterItemReader.read(). This method is called only for actual items (that is, it is not called when the reader returnsnull).- Specified by:
afterReadin interfaceItemReadListener<T>- Parameters:
item- returned from read()- See Also:
-
beforeRead
public void beforeRead()Description copied from interface:ItemReadListenerCalled beforeItemReader.read()- Specified by:
beforeReadin interfaceItemReadListener<T>- See Also:
-
onReadError
Description copied from interface:ItemReadListenerCalled if an error occurs while trying to read.- Specified by:
onReadErrorin interfaceItemReadListener<T>- Parameters:
ex- thrown fromItemReader- See Also:
-
afterWrite
Description copied from interface:ItemWriteListenerCalled afterItemWriter.write(Chunk). This is called before any transaction is committed, and beforeChunkListener.afterChunk(ChunkContext).- Specified by:
afterWritein interfaceItemWriteListener<T>- Parameters:
items- written items- See Also:
-
beforeWrite
Description copied from interface:ItemWriteListenerCalled beforeItemWriter.write(Chunk)- Specified by:
beforeWritein interfaceItemWriteListener<T>- Parameters:
items- to be written- See Also:
-
onWriteError
Description copied from interface:ItemWriteListenerCalled if an error occurs while trying to write. Called inside a transaction, but the transaction will normally be rolled back. There is no way to identify from this callback which of the items (if any) caused the error.- Specified by:
onWriteErrorin interfaceItemWriteListener<T>- Parameters:
ex- thrown fromItemWriteritems- attempted to be written.- See Also:
-
onSkipInRead
Description copied from interface:SkipListenerCallback for a failure on read that is legal and, consequently, is not going to be re-thrown. In case a transaction is rolled back and items are re-read, this callback occurs repeatedly for the same cause. This happens only if read items are not buffered.- Specified by:
onSkipInReadin interfaceSkipListener<T,S> - Parameters:
t- cause of the failure- See Also:
-
onSkipInWrite
Description copied from interface:SkipListenerThis item failed on write with the given exception, and a skip was called for.- Specified by:
onSkipInWritein interfaceSkipListener<T,S> - Parameters:
item- the failed itemt- the cause of the failure- See Also:
-
onSkipInProcess
Description copied from interface:SkipListenerThis item failed on processing with the given exception, and a skip was called for.- Specified by:
onSkipInProcessin interfaceSkipListener<T,S> - Parameters:
item- the failed itemt- the cause of the failure- See Also:
-
afterChunkError
Description copied from interface:ChunkListenerCallback after a chunk has been marked for rollback. It is invoked after transaction rollback. While the rollback will have occurred, transactional resources might still be active and accessible. Due to this, data access code within this callback still "participates" in the original transaction unless it declares that it runs in its own transaction. As a result, you should usePROPAGATION_REQUIRES_NEWfor any transactional operation that is called from here.- Specified by:
afterChunkErrorin interfaceChunkListener- Parameters:
context- the chunk context containing the exception that caused the underlying rollback.
-