org.axonframework.unitofwork
Interface UnitOfWorkListener

All Known Implementing Classes:
AuditingUnitOfWorkListener, MetaDataMutatingUnitOfWorkListenerAdapter, UnitOfWorkListenerAdapter, UnitOfWorkListenerCollection

public interface UnitOfWorkListener

Interface describing a listener that is notified of state changes in the UnitOfWork it has been registered with.

Since:
0.6
Author:
Allard Buijze

Method Summary
 void afterCommit(UnitOfWork unitOfWork)
          Invoked when the UnitOfWork is committed.
 void onCleanup(UnitOfWork unitOfWork)
          Notifies listeners that the UnitOfWork is being cleaned up.
<T> EventMessage<T>
onEventRegistered(UnitOfWork unitOfWork, EventMessage<T> event)
          Invoked when an Event is registered for publication when the UnitOfWork is committed.
 void onPrepareCommit(UnitOfWork unitOfWork, Set<AggregateRoot> aggregateRoots, List<EventMessage> events)
          Invoked before aggregates are committed, and before any events are published.
 void onPrepareTransactionCommit(UnitOfWork unitOfWork, Object transaction)
          Invoked before the transaction bound to this Unit of Work is committed, but after all other commit activities (publication of events and saving of aggregates) are performed.
 void onRollback(UnitOfWork unitOfWork, Throwable failureCause)
          Invoked when the UnitOfWork is rolled back.
 

Method Detail

afterCommit

void afterCommit(UnitOfWork unitOfWork)
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 onRollback(UnitOfWork, Throwable) consecutively.

Parameters:
unitOfWork - The Unit of Work being committed
See Also:
UnitOfWork.commit()

onRollback

void onRollback(UnitOfWork unitOfWork,
                Throwable failureCause)
Invoked when the UnitOfWork is rolled back. The UnitOfWork may choose to invoke this method when committing the UnitOfWork failed, too.

Parameters:
unitOfWork - The Unit of Work being rolled back
failureCause - The exception (or error) causing the roll back
See Also:
UnitOfWork.rollback(Throwable)

onEventRegistered

<T> EventMessage<T> onEventRegistered(UnitOfWork unitOfWork,
                                      EventMessage<T> event)
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.

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

onPrepareCommit

void onPrepareCommit(UnitOfWork unitOfWork,
                     Set<AggregateRoot> aggregateRoots,
                     List<EventMessage> events)
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.

Parameters:
unitOfWork - The Unit of Work being committed
aggregateRoots - the aggregate roots being committed
events - Events that have been registered for dispatching with the UnitOfWork

onPrepareTransactionCommit

void onPrepareTransactionCommit(UnitOfWork unitOfWork,
                                Object transaction)
Invoked before the transaction bound to this Unit of Work is committed, but after all other commit activities (publication of events and saving of aggregates) are performed. This gives resource manager the opportunity to take actions that must be part of the same transaction.

Note that this method is only invoked if the Unit of Work is bound to a transaction.

Parameters:
unitOfWork - The Unit of Work of which the underlying transaction is being committed.
transaction - The object representing the (status of) the transaction, as returned by TransactionManager.startTransaction().
See Also:
TransactionManager

onCleanup

void onCleanup(UnitOfWork unitOfWork)
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.

Parameters:
unitOfWork - The Unit of Work being cleaned up


Copyright © 2010-2016. All Rights Reserved.