org.axonframework.unitofwork
Class MetaDataMutatingUnitOfWorkListenerAdapter

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

public abstract class MetaDataMutatingUnitOfWorkListenerAdapter
extends UnitOfWorkListenerAdapter

Specialist UnitOfWorkListenerAdapter that allows modification of Meta Data of Events during the "beforeCommit" phase of a Unit of Work. This is the phase where all events to publish are known, but haven't been persisted or published yet.

Since:
2.1
Author:
Allard Buijze

Constructor Summary
MetaDataMutatingUnitOfWorkListenerAdapter()
           
 
Method Summary
protected abstract  Map<String,?> assignMetaData(EventMessage event, List<EventMessage> events, int index)
          Defines the additional meta data to assign to the given event.
<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.
 
Methods inherited from class org.axonframework.unitofwork.UnitOfWorkListenerAdapter
afterCommit, onCleanup, onPrepareTransactionCommit, onRollback
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MetaDataMutatingUnitOfWorkListenerAdapter

public MetaDataMutatingUnitOfWorkListenerAdapter()
Method Detail

onEventRegistered

public final <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

onPrepareCommit

public void onPrepareCommit(UnitOfWork unitOfWork,
                            Set<AggregateRoot> aggregateRoots,
                            List<EventMessage> events)
Description copied from class: UnitOfWorkListenerAdapter
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
Overrides:
onPrepareCommit in class UnitOfWorkListenerAdapter
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

assignMetaData

protected abstract Map<String,?> assignMetaData(EventMessage event,
                                                List<EventMessage> events,
                                                int index)
Defines the additional meta data to assign to the given event. For reference, the entire list of events is provided, where the given event can be found at given index.

Any entries returned that already exist are overwritten by the entry in the Map returned. Other entries are added.

This method is invoked for each of the events.

Parameters:
event - The event for which to assign additional meta data
events - The entire list of events part of this unit of work
index - The index at which the event can be found in the list of events
Returns:
a Map with entries to add to the Meta Data of the given event


Copyright © 2010-2016. All Rights Reserved.