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 TypeMethodDescriptionvoid
afterChunk
(ChunkContext context) Callback after the chunk is executed, outside the transaction.void
afterChunkError
(ChunkContext context) Callback after a chunk has been marked for rollback.void
afterProcess
(T item, S result) Called afterItemProcessor.process(Object)
returns.void
Called afterItemReader.read()
.afterStep
(StepExecution stepExecution) Give a listener a chance to modify the exit status from a step.void
afterWrite
(List<? extends S> items) Called afterItemWriter.write(java.util.List)
.void
beforeChunk
(ChunkContext context) Callback before the chunk is executed, but inside the transaction.void
beforeProcess
(T item) Called beforeItemProcessor.process(Object)
.void
Called beforeItemReader.read()
void
beforeStep
(StepExecution stepExecution) Initialize the state of the listener with theStepExecution
from the current scope.void
beforeWrite
(List<? extends S> items) Called beforeItemWriter.write(java.util.List)
void
onProcessError
(T item, Exception ex) Called if an exception was thrown fromItemProcessor.process(Object)
.void
onReadError
(Exception ex) Called if an error occurs while trying to read.void
onSkipInProcess
(T item, Throwable t) This item failed on processing with the given exception, and a skip was called for.void
Callback for a failure on read that is legal and, consequently, is not going to be re-thrown.void
onSkipInWrite
(S item, Throwable t) This item failed on write with the given exception, and a skip was called for.void
onWriteError
(Exception ex, List<? extends S> items) Called if an error occurs while trying to write.void
register
(StepListener listener) Register the listener for callbacks on the appropriate interfaces implemented.void
setListeners
(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 theMulticasterBatchListener
broadcast 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. AnyStepListener
can be provided, or anItemStream
. Other types will be ignored.- Parameters:
listener
- theStepListener
instance to be registered.
-
afterProcess
Description copied from interface:ItemProcessListener
Called afterItemProcessor.process(Object)
returns. If the processor returnsnull
, this method is still called, with anull
result, allowing for notification of "filtered" items.- Specified by:
afterProcess
in interfaceItemProcessListener<T,
S> - Parameters:
item
- to be processedresult
- of processing- See Also:
-
beforeProcess
Description copied from interface:ItemProcessListener
Called beforeItemProcessor.process(Object)
.- Specified by:
beforeProcess
in interfaceItemProcessListener<T,
S> - Parameters:
item
- to be processed.- See Also:
-
onProcessError
Description copied from interface:ItemProcessListener
Called if an exception was thrown fromItemProcessor.process(Object)
.- Specified by:
onProcessError
in interfaceItemProcessListener<T,
S> - Parameters:
item
- attempted to be processedex
- - exception thrown during processing.- See Also:
-
afterStep
Description copied from interface:StepExecutionListener
Give 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:
afterStep
in interfaceStepExecutionListener
- Parameters:
stepExecution
- aStepExecution
instance.- Returns:
- an
ExitStatus
to combine with the normal value. Returnnull
(the default) to leave the old value unchanged. - See Also:
-
beforeStep
Description copied from interface:StepExecutionListener
Initialize the state of the listener with theStepExecution
from the current scope.- Specified by:
beforeStep
in interfaceStepExecutionListener
- Parameters:
stepExecution
- instance ofStepExecution
.- See Also:
-
afterChunk
Description copied from interface:ChunkListener
Callback after the chunk is executed, outside the transaction.- Specified by:
afterChunk
in interfaceChunkListener
- Parameters:
context
- The currentChunkContext
- See Also:
-
beforeChunk
Description copied from interface:ChunkListener
Callback before the chunk is executed, but inside the transaction.- Specified by:
beforeChunk
in interfaceChunkListener
- Parameters:
context
- The currentChunkContext
- See Also:
-
afterRead
Description copied from interface:ItemReadListener
Called afterItemReader.read()
. This method is called only for actual items (that is, it is not called when the reader returnsnull
).- Specified by:
afterRead
in interfaceItemReadListener<T>
- Parameters:
item
- returned from read()- See Also:
-
beforeRead
public void beforeRead()Description copied from interface:ItemReadListener
Called beforeItemReader.read()
- Specified by:
beforeRead
in interfaceItemReadListener<T>
- See Also:
-
onReadError
Description copied from interface:ItemReadListener
Called if an error occurs while trying to read.- Specified by:
onReadError
in interfaceItemReadListener<T>
- Parameters:
ex
- thrown fromItemReader
- See Also:
-
afterWrite
Description copied from interface:ItemWriteListener
Called afterItemWriter.write(java.util.List)
. This is called before any transaction is committed, and beforeChunkListener.afterChunk(ChunkContext)
.- Specified by:
afterWrite
in interfaceItemWriteListener<T>
- Parameters:
items
- written items- See Also:
-
beforeWrite
Description copied from interface:ItemWriteListener
Called beforeItemWriter.write(java.util.List)
- Specified by:
beforeWrite
in interfaceItemWriteListener<T>
- Parameters:
items
- to be written- See Also:
-
onWriteError
Description copied from interface:ItemWriteListener
Called 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:
onWriteError
in interfaceItemWriteListener<T>
- Parameters:
ex
- thrown fromItemWriter
items
- attempted to be written.- See Also:
-
onSkipInRead
Description copied from interface:SkipListener
Callback 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:
onSkipInRead
in interfaceSkipListener<T,
S> - Parameters:
t
- cause of the failure- See Also:
-
onSkipInWrite
Description copied from interface:SkipListener
This item failed on write with the given exception, and a skip was called for.- Specified by:
onSkipInWrite
in interfaceSkipListener<T,
S> - Parameters:
item
- the failed itemt
- the cause of the failure- See Also:
-
onSkipInProcess
Description copied from interface:SkipListener
This item failed on processing with the given exception, and a skip was called for.- Specified by:
onSkipInProcess
in interfaceSkipListener<T,
S> - Parameters:
item
- the failed itemt
- the cause of the failure- See Also:
-
afterChunkError
Description copied from interface:ChunkListener
Callback 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_NEW
for any transactional operation that is called from here.- Specified by:
afterChunkError
in interfaceChunkListener
- Parameters:
context
- the chunk context containing the exception that caused the underlying rollback.
-