org.axonframework.auditing
Class AuditingUnitOfWorkListener

java.lang.Object
  extended by org.axonframework.unitofwork.UnitOfWorkListenerAdapter
      extended by org.axonframework.auditing.AuditingUnitOfWorkListener
All Implemented Interfaces:
UnitOfWorkListener

public class AuditingUnitOfWorkListener
extends UnitOfWorkListenerAdapter

Listener implementation that adds auditing information to events being tracked by the unit of work this listener is registered to.

Since:
0.7
Author:
Allard Buijze

Constructor Summary
AuditingUnitOfWorkListener(CommandMessage<?> command, AuditDataProvider auditDataProvider, AuditLogger auditLogger)
          Initialize a listener for the given command.
 
Method Summary
 void afterCommit(UnitOfWork unitOfWork)
          Invoked when the UnitOfWork is committed.
<T> EventMessage<T>
onEventRegistered(UnitOfWork unitOfWork, EventMessage<T> event)
          Invoked when an Event is registered for publication when the UnitOfWork is committed.
 void onRollback(UnitOfWork unitOfWork, Throwable failureCause)
          Invoked when the UnitOfWork is rolled back.
 
Methods inherited from class org.axonframework.unitofwork.UnitOfWorkListenerAdapter
onCleanup, onPrepareCommit, onPrepareTransactionCommit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AuditingUnitOfWorkListener

public AuditingUnitOfWorkListener(CommandMessage<?> command,
                                  AuditDataProvider auditDataProvider,
                                  AuditLogger auditLogger)
Initialize a listener for the given command. The auditDataProvider is called before the Unit Of Work is committed to provide the auditing information. The auditLogger is invoked after the Unit Of Work is successfully committed.

Parameters:
command - The command being audited
auditDataProvider - The instance providing the information to attach to the events
auditLogger - The logger writing the audit
Method Detail

afterCommit

public void afterCommit(UnitOfWork unitOfWork)
Description copied from class: UnitOfWorkListenerAdapter
Invoked when the UnitOfWork is committed. The aggregate has been saved and the events have been scheduled for dispatching. In some cases, the events could already have been dispatched. When processing of this method causes an exception, a UnitOfWork may choose to call UnitOfWorkListener.onRollback(UnitOfWork, Throwable) consecutively.

Specified by:
afterCommit in interface UnitOfWorkListener
Overrides:
afterCommit in class UnitOfWorkListenerAdapter
Parameters:
unitOfWork - The Unit of Work being committed
See Also:
UnitOfWork.commit()

onRollback

public void onRollback(UnitOfWork unitOfWork,
                       Throwable failureCause)
Description copied from class: UnitOfWorkListenerAdapter
Invoked when the UnitOfWork is rolled back. The UnitOfWork may choose to invoke this method when committing the UnitOfWork failed, too.

Specified by:
onRollback in interface UnitOfWorkListener
Overrides:
onRollback in class UnitOfWorkListenerAdapter
Parameters:
unitOfWork - The Unit of Work being rolled back
failureCause - The exception (or error) causing the roll back
See Also:
UnitOfWork.rollback(Throwable)

onEventRegistered

public <T> EventMessage<T> onEventRegistered(UnitOfWork unitOfWork,
                                             EventMessage<T> event)
Description copied from class: UnitOfWorkListenerAdapter
Invoked when an Event is registered for publication when the UnitOfWork is committed. Listeners may alter Event information by returning a new instance for the event. Note that the Listener must ensure the functional meaning of the EventMessage does not change. Typically, this is done by only modifying the MetaData on an Event.

The simplest implementation simply returns the given event.

Specified by:
onEventRegistered in interface UnitOfWorkListener
Overrides:
onEventRegistered in class UnitOfWorkListenerAdapter
Type Parameters:
T - The type of payload of the EventMessage
Parameters:
unitOfWork - The Unit of Work on which an event is registered
event - The event about to be registered for publication
Returns:
the (modified) event to register for publication


Copyright © 2010-2016. All Rights Reserved.