org.springframework.batch.core.listener
Class MulticasterBatchListener

java.lang.Object
  extended by org.springframework.batch.core.listener.MulticasterBatchListener
All Implemented Interfaces:
ChunkListener, ItemReadListener, ItemWriteListener, SkipListener, StepExecutionListener, StepListener

public class MulticasterBatchListener
extends Object
implements StepExecutionListener, ChunkListener, ItemReadListener, ItemWriteListener, SkipListener

Author:
Dave Syer

Constructor Summary
MulticasterBatchListener()
          Initialise the listener instance.
 
Method Summary
 void afterChunk()
          Callback after the chunk is executed, but inside the transaction.
 void afterRead(Object item)
          Called after ItemReader.read()
 ExitStatus afterStep(StepExecution stepExecution)
          Give a listener a chance to modify the exit status from a step.
 void afterWrite(Object item)
          Called after ItemWriter.write(Object) If the item is last in a chunk, this will be called before any transaction is committed, and before ChunkListener.afterChunk()
 void beforeChunk()
          Callback before the chunk is executed, but inside the transaction.
 void beforeRead()
          Called before ItemReader.read()
 void beforeStep(StepExecution stepExecution)
          Initialise the state of the listener with the StepExecution from the current scope.
 void beforeWrite(Object item)
          Called before ItemWriter.write(Object)
 ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e)
          The value returned will be combined with the normal exit status using ExitStatus.and(ExitStatus).
 void onReadError(Exception ex)
          Called if an error occurs while trying to write.
 void onSkipInRead(Throwable t)
          Callback for a failure on read that is legal, so is not going to be re-thrown.
 void onSkipInWrite(Object item, Throwable t)
          This item failed on write with the given exception, and a skip was called for.
 void onWriteError(Exception ex, Object item)
          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(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 Detail

MulticasterBatchListener

public MulticasterBatchListener()
Initialise the listener instance.

Method Detail

setListeners

public void setListeners(StepListener[] listeners)
Register each of the objects as listeners. Once registered, calls to the MulticasterBatchListener broadcast to the individual listeners.

Parameters:
listeners - an array of 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.


afterStep

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 successful execution of step's processing logic. Throwing exception in this method will cause step to fail.

Specified by:
afterStep in interface StepExecutionListener
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
Initialise the state of the listener with the StepExecution from the current scope.

Specified by:
beforeStep in interface StepExecutionListener
Parameters:
stepExecution -
See Also:
CompositeStepExecutionListener.beforeStep(org.springframework.batch.core.StepExecution)

onErrorInStep

public ExitStatus onErrorInStep(StepExecution stepExecution,
                                Throwable e)
Description copied from interface: StepExecutionListener
The value returned will be combined with the normal exit status using ExitStatus.and(ExitStatus).

Specified by:
onErrorInStep in interface StepExecutionListener
Parameters:
e -
Returns:
an exit status to be combined with the normal one, or null
See Also:
CompositeStepExecutionListener.onErrorInStep(StepExecution, Throwable)

afterChunk

public void afterChunk()
Description copied from interface: ChunkListener
Callback after the chunk is executed, but inside the transaction.

Specified by:
afterChunk in interface ChunkListener
See Also:
CompositeChunkListener.afterChunk()

beforeChunk

public void beforeChunk()
Description copied from interface: ChunkListener
Callback before the chunk is executed, but inside the transaction.

Specified by:
beforeChunk in interface ChunkListener
See Also:
CompositeChunkListener.beforeChunk()

afterRead

public void afterRead(Object item)
Description copied from interface: ItemReadListener
Called after ItemReader.read()

Specified by:
afterRead in interface ItemReadListener
Parameters:
item -
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
See Also:
CompositeItemReadListener.beforeRead()

onReadError

public void onReadError(Exception ex)
Description copied from interface: ItemReadListener
Called if an error occurs while trying to write.

Specified by:
onReadError in interface ItemReadListener
Parameters:
ex -
See Also:
CompositeItemReadListener.onReadError(java.lang.Exception)

afterWrite

public void afterWrite(Object item)
Description copied from interface: ItemWriteListener
Called after ItemWriter.write(Object) If the item is last in a chunk, this will be called before any transaction is committed, and before ChunkListener.afterChunk()

Specified by:
afterWrite in interface ItemWriteListener
Parameters:
item - written item
See Also:
CompositeItemWriteListener.afterWrite(Object)

beforeWrite

public void beforeWrite(Object item)
Description copied from interface: ItemWriteListener
Called before ItemWriter.write(Object)

Specified by:
beforeWrite in interface ItemWriteListener
Parameters:
item -
See Also:
CompositeItemWriteListener.beforeWrite(java.lang.Object)

onWriteError

public void onWriteError(Exception ex,
                         Object item)
Description copied from interface: ItemWriteListener
Called if an error occurs while trying to write.

Specified by:
onWriteError in interface ItemWriteListener
Parameters:
ex -
item -
See Also:
CompositeItemWriteListener.onWriteError(java.lang.Exception, java.lang.Object)

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.

Specified by:
onSkipInRead in interface SkipListener
Parameters:
t -
See Also:
CompositeSkipListener.onSkipInRead(java.lang.Throwable)

onSkipInWrite

public void onSkipInWrite(Object item,
                          Throwable t)
Description copied from interface: SkipListener
This item failed on write with the given exception, and a skip was called for. The callback is deferred until a new transaction is available. This callback might occur more than once for the same item, but only once in successful transaction.

Specified by:
onSkipInWrite in interface SkipListener
Parameters:
item -
t -
See Also:
CompositeSkipListener.onSkipInWrite(java.lang.Object, java.lang.Throwable)


Copyright © 2008 SpringSource. All Rights Reserved.