org.axonframework.auditing
Class AuditingUnitOfWorkListener

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

public class AuditingUnitOfWorkListener
extends Object
implements UnitOfWorkListener

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(Object command, AuditDataProvider auditDataProvider, AuditLogger auditLogger)
          Initialize a listener for the given command.
 
Method Summary
 void afterCommit()
          Invoked when the UnitOfWork is committed.
 void onCleanup()
          Notifies listeners that the UnitOfWork is being cleaned up.
 void onPrepareCommit(Set<AggregateRoot> aggregateRoots, List<Event> events)
          Invoked before aggregates are committed, and before any events are published.
 void onRollback(Throwable failureCause)
          Invoked when the UnitOfWork is rolled back.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AuditingUnitOfWorkListener

public AuditingUnitOfWorkListener(Object 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()
Description copied from interface: UnitOfWorkListener
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(Throwable) consecutively.

Specified by:
afterCommit in interface UnitOfWorkListener
See Also:
UnitOfWork.commit()

onRollback

public void onRollback(Throwable failureCause)
Description copied from interface: UnitOfWorkListener
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
Parameters:
failureCause - The exception (or error) causing the roll back
See Also:
UnitOfWork.rollback(Throwable)

onPrepareCommit

public void onPrepareCommit(Set<AggregateRoot> aggregateRoots,
                            List<Event> events)
Description copied from interface: UnitOfWorkListener
Invoked before aggregates are committed, and before any events are published. This phase can be used to do validation or other activity that should be able to prevent event dispatching in certain circumstances.

Note that the given events may not contain the uncommitted domain events of each of the aggregateRoots. To retrieve all events, collect all uncommitted events from the aggregate roots and combine them with the list of events.

Specified by:
onPrepareCommit in interface UnitOfWorkListener
Parameters:
aggregateRoots - the aggregate roots being committed
events - Events that have been registered for dispatching with the UnitOfWork

onCleanup

public void onCleanup()
Description copied from interface: UnitOfWorkListener
Notifies listeners that the UnitOfWork is being cleaned up. This gives listeners the opportunity to clean up resources that might have been used during commit or rollback, such as remaining locks, open files, etc.

This method is always called after all listeners have been notified of a commit or rollback.

Specified by:
onCleanup in interface UnitOfWorkListener


Copyright © 2011. All Rights Reserved.