Package org.springframework.batch.core.listener

# 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
  Constructor
  Description
  `MulticasterBatchListener()`
  Initialize the listener instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `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 after `ItemProcessor.process(Object)` returns.
  `void`
  `afterRead(T item)`
  Called after `ItemReader.read()`.
  `ExitStatus`
  `afterStep(StepExecution stepExecution)`
  Give a listener a chance to modify the exit status from a step.
  `void`
  `afterWrite(List<? extends S> items)`
  Called after `ItemWriter.write(java.util.List)` This will be called before any transaction is committed, and before `ChunkListener.afterChunk(ChunkContext)`
  `void`
  `beforeChunk(ChunkContext context)`
  Callback before the chunk is executed, but inside the transaction.
  `void`
  `beforeProcess(T item)`
  Called before `ItemProcessor.process(Object)`.
  `void`
  `beforeRead()`
  Called before `ItemReader.read()`
  `void`
  `beforeStep(StepExecution stepExecution)`
  Initialize the state of the listener with the `StepExecution` from the current scope.
  `void`
  `beforeWrite(List<? extends S> items)`
  Called before `ItemWriter.write(java.util.List)`
  `void`
  `onProcessError(T item, Exception ex)`
  Called if an exception was thrown from `ItemProcessor.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`
  `onSkipInRead(Throwable t)`
  Callback for a failure on read that is legal, so 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.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### MulticasterBatchListener

    public MulticasterBatchListener()
    Initialize the listener instance.

- ## Method Details

  - ### setListeners

    public void setListeners(List<? extends StepListener> listeners)
    Register each of the objects as listeners. Once registered, calls to the `MulticasterBatchListener` broadcast to the individual listeners.
    Parameters:
      `listeners` - listener objects of types known to the multicaster.

  - ### register

    public void register(StepListener listener)
    Register the listener for callbacks on the appropriate interfaces implemented. Any `StepListener` can be provided, or an `ItemStream`. Other types will be ignored.
    Parameters:
      `listener` - the `StepListener` instance to be registered.

  - ### afterProcess

    public void afterProcess(T item, @Nullable S result)
    Description copied from interface: `ItemProcessListener`
    Called after `ItemProcessor.process(Object)` returns. If the processor returns `null`, this method will still be called, with a {code null} result, allowing for notification of 'filtered' items.
    Specified by:
      `afterProcess` in interface `ItemProcessListener<T,S>`
    Parameters:
      `item` - to be processed
      `result` - of processing
    See Also:
      - `CompositeItemProcessListener.afterProcess(java.lang.Object, java.lang.Object)`

  - ### beforeProcess

    public void beforeProcess(T item)
    Description copied from interface: `ItemProcessListener`
    Called before `ItemProcessor.process(Object)`.
    Specified by:
      `beforeProcess` in interface `ItemProcessListener<T,S>`
    Parameters:
      `item` - to be processed.
    See Also:
      - `CompositeItemProcessListener.beforeProcess(java.lang.Object)`

  - ### onProcessError

    public void onProcessError(T item, Exception ex)
    Description copied from interface: `ItemProcessListener`
    Called if an exception was thrown from `ItemProcessor.process(Object)`.
    Specified by:
      `onProcessError` in interface `ItemProcessListener<T,S>`
    Parameters:
      `item` - attempted to be processed
      `ex` - - exception thrown during processing.
    See Also:
      - `CompositeItemProcessListener.onProcessError(java.lang.Object, java.lang.Exception)`

  - ### afterStep

    @Nullable public ExitStatus afterStep(StepExecution stepExecution)
    Description copied from interface: `StepExecutionListener`
    Give a listener a chance to modify the exit status from a step. The value returned will be combined with the normal exit status using `ExitStatus.and(ExitStatus)`. Called after execution of step's processing logic (both successful or failed). Throwing exception in this method has no effect, it will only be logged.
    Specified by:
      `afterStep` in interface `StepExecutionListener`
    Parameters:
      `stepExecution` - `StepExecution` instance.
    Returns:
      an `ExitStatus` to combine with the normal value. Return `null` to leave the old value unchanged.
    See Also:
      - `CompositeStepExecutionListener.afterStep(StepExecution)`

  - ### beforeStep

    public void beforeStep(StepExecution stepExecution)
    Description copied from interface: `StepExecutionListener`
    Initialize the state of the listener with the `StepExecution` from the current scope.
    Specified by:
      `beforeStep` in interface `StepExecutionListener`
    Parameters:
      `stepExecution` - instance of `StepExecution`.
    See Also:
      - `CompositeStepExecutionListener.beforeStep(org.springframework.batch.core.StepExecution)`

  - ### afterChunk

    public void afterChunk(ChunkContext context)
    Description copied from interface: `ChunkListener`
    Callback after the chunk is executed, outside the transaction.
    Specified by:
      `afterChunk` in interface `ChunkListener`
    Parameters:
      `context` - The current `ChunkContext`
    See Also:
      - `CompositeChunkListener.afterChunk(ChunkContext context)`

  - ### beforeChunk

    public void beforeChunk(ChunkContext context)
    Description copied from interface: `ChunkListener`
    Callback before the chunk is executed, but inside the transaction.
    Specified by:
      `beforeChunk` in interface `ChunkListener`
    Parameters:
      `context` - The current `ChunkContext`
    See Also:
      - `CompositeChunkListener.beforeChunk(ChunkContext context)`

  - ### afterRead

    public void afterRead(T item)
    Description copied from interface: `ItemReadListener`
    Called after `ItemReader.read()`. This method is called only for actual items (ie it is not called when the reader returns null).
    Specified by:
      `afterRead` in interface `ItemReadListener<T>`
    Parameters:
      `item` - returned from read()
    See Also:
      - `CompositeItemReadListener.afterRead(java.lang.Object)`

  - ### beforeRead

    public void beforeRead()
    Description copied from interface: `ItemReadListener`
    Called before `ItemReader.read()`
    Specified by:
      `beforeRead` in interface `ItemReadListener<T>`
    See Also:
      - `CompositeItemReadListener.beforeRead()`

  - ### onReadError

    public void onReadError(Exception ex)
    Description copied from interface: `ItemReadListener`
    Called if an error occurs while trying to read.
    Specified by:
      `onReadError` in interface `ItemReadListener<T>`
    Parameters:
      `ex` - thrown from `ItemReader`
    See Also:
      - `CompositeItemReadListener.onReadError(java.lang.Exception)`

  - ### afterWrite

    public void afterWrite(List<? extends S> items)
    Description copied from interface: `ItemWriteListener`
    Called after `ItemWriter.write(java.util.List)` This will be called before any transaction is committed, and before `ChunkListener.afterChunk(ChunkContext)`
    Specified by:
      `afterWrite` in interface `ItemWriteListener<T>`
    Parameters:
      `items` - written items
    See Also:
      - `ItemWriteListener.afterWrite(List)`

  - ### beforeWrite

    public void beforeWrite(List<? extends S> items)
    Description copied from interface: `ItemWriteListener`
    Called before `ItemWriter.write(java.util.List)`
    Specified by:
      `beforeWrite` in interface `ItemWriteListener<T>`
    Parameters:
      `items` - to be written
    See Also:
      - `ItemWriteListener.beforeWrite(List)`

  - ### onWriteError

    public void onWriteError(Exception ex, List<? extends S> items)
    Description copied from interface: `ItemWriteListener`
    Called if an error occurs while trying to write. Will be 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 interface `ItemWriteListener<T>`
    Parameters:
      `ex` - thrown from `ItemWriter`
      `items` - attempted to be written.
    See Also:
      - `ItemWriteListener.onWriteError(Exception, List)`

  - ### onSkipInRead

    public void onSkipInRead(Throwable t)
    Description copied from interface: `SkipListener`
    Callback for a failure on read that is legal, so is not going to be re-thrown. In case transaction is rolled back and items are re-read, this callback will occur repeatedly for the same cause. This will only happen if read items are not buffered.
    Specified by:
      `onSkipInRead` in interface `SkipListener<T,S>`
    Parameters:
      `t` - cause of the failure
    See Also:
      - `CompositeSkipListener.onSkipInRead(java.lang.Throwable)`

  - ### onSkipInWrite

    public void onSkipInWrite(S item, Throwable t)
    Description copied from interface: `SkipListener`
    This item failed on write with the given exception, and a skip was called for.
    Specified by:
      `onSkipInWrite` in interface `SkipListener<T,S>`
    Parameters:
      `item` - the failed item
      `t` - the cause of the failure
    See Also:
      - `CompositeSkipListener.onSkipInWrite(java.lang.Object, java.lang.Throwable)`

  - ### onSkipInProcess

    public void onSkipInProcess(T item, Throwable t)
    Description copied from interface: `SkipListener`
    This item failed on processing with the given exception, and a skip was called for.
    Specified by:
      `onSkipInProcess` in interface `SkipListener<T,S>`
    Parameters:
      `item` - the failed item
      `t` - the cause of the failure
    See Also:
      - `CompositeSkipListener.onSkipInProcess(Object, Throwable)`

  - ### afterChunkError

    public void afterChunkError(ChunkContext context)
    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 will still "participate" in the original transaction unless it declares that it runs in its own transaction. Hence: Use PROPAGATION_REQUIRES_NEW for any transactional operation that is called from here.
    Specified by:
      `afterChunkError` in interface `ChunkListener`
    Parameters:
      `context` - the chunk context containing the exception that caused the underlying rollback.