org.axonframework.domain
Class EventContainer

java.lang.Object
  extended by org.axonframework.domain.EventContainer
All Implemented Interfaces:
Serializable

public class EventContainer
extends Object
implements Serializable

Container for events related to a single aggregate. The container will wrap registered event (payload) and metadata in an DomainEventMessage and automatically assign the aggregate identifier and the next sequence number.

The EventContainer also takes care of the invocation of EventRegistrationCallbacks once events are registered with this aggregate for publication.

This implementation is not thread safe and should only be used with proper locking in place. Generally, only a single thread will be modifying an aggregate at any given time.

Since:
0.1
Author:
Allard Buijze
See Also:
DomainEventMessage, AbstractAggregateRoot, Serialized Form

Constructor Summary
EventContainer(Object aggregateIdentifier)
          Initialize an EventContainer for an aggregate with the given aggregateIdentifier.
 
Method Summary
<T> DomainEventMessage<T>
addEvent(DomainEventMessage<T> domainEventMessage)
          Add an event to this container.
<T> DomainEventMessage<T>
addEvent(MetaData metaData, T payload)
          Add an event to this container.
 void addEventRegistrationCallback(EventRegistrationCallback eventRegistrationCallback)
          Adds an EventRegistrationCallback, which is invoked when the aggregate owning this container registers an Event.
 void commit()
          Clears the events in this container.
 Object getAggregateIdentifier()
          Returns the aggregate identifier assigned to this container.
 List<DomainEventMessage> getEventList()
          Returns an unmodifiable version of the backing list of events.
 DomainEventStream getEventStream()
          Read the events inside this container using a DomainEventStream.
 Long getLastCommittedSequenceNumber()
          Returns the sequence number of the last committed event, or null if no events have been committed.
 Long getLastSequenceNumber()
          Returns the sequence number of the event last added to this container.
 void initializeSequenceNumber(Long lastKnownSequenceNumber)
          Sets the first sequence number that should be assigned to an incoming event.
 int size()
          Returns the number of events currently inside this container.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventContainer

public EventContainer(Object aggregateIdentifier)
Initialize an EventContainer for an aggregate with the given aggregateIdentifier. This identifier will be attached to all incoming events.

Parameters:
aggregateIdentifier - the aggregate identifier to assign to this container
Method Detail

addEvent

public <T> DomainEventMessage<T> addEvent(MetaData metaData,
                                          T payload)
Add an event to this container.

Events should either be already assigned to the aggregate with the same identifier as this container, or have no aggregate assigned yet. If an event has a sequence number assigned, it must follow directly upon the sequence number of the event that was previously added.

Type Parameters:
T - the type of payload contained in the event
Parameters:
metaData - the metaData of the event to add to this container
payload - the payload of the event to add to this container
Returns:
the DomainEventMessage added to the container

addEvent

public <T> DomainEventMessage<T> addEvent(DomainEventMessage<T> domainEventMessage)
Add an event to this container.

Events should either be already assigned to the aggregate with the same identifier as this container, or have no aggregate assigned yet. If an event has a sequence number assigned, it must follow directly upon the sequence number of the event that was previously added.

Type Parameters:
T - the type of payload contained in the event
Parameters:
domainEventMessage - The message containing the event to add to the container
Returns:
the DomainEventMessage added to the container

getEventStream

public DomainEventStream getEventStream()
Read the events inside this container using a DomainEventStream. The returned stream is a snapshot of the uncommitted events in the aggregate at the time of the invocation. Once returned, newly applied events are not accessible from the returned event stream.

Returns:
a DomainEventStream providing access to the events in this container

getAggregateIdentifier

public Object getAggregateIdentifier()
Returns the aggregate identifier assigned to this container.

Returns:
the aggregate identifier assigned to this container

initializeSequenceNumber

public void initializeSequenceNumber(Long lastKnownSequenceNumber)
Sets the first sequence number that should be assigned to an incoming event.

Parameters:
lastKnownSequenceNumber - the sequence number of the last known event

getLastSequenceNumber

public Long getLastSequenceNumber()
Returns the sequence number of the event last added to this container.

Returns:
the sequence number of the last event

getLastCommittedSequenceNumber

public Long getLastCommittedSequenceNumber()
Returns the sequence number of the last committed event, or null if no events have been committed.

Returns:
the sequence number of the last committed event

commit

public void commit()
Clears the events in this container. The sequence number is not modified by this call.


size

public int size()
Returns the number of events currently inside this container.

Returns:
the number of events in this container

getEventList

public List<DomainEventMessage> getEventList()
Returns an unmodifiable version of the backing list of events.

Returns:
a list containing the events in this container

addEventRegistrationCallback

public void addEventRegistrationCallback(EventRegistrationCallback eventRegistrationCallback)
Adds an EventRegistrationCallback, which is invoked when the aggregate owning this container registers an Event. These callbacks are cleared when the Events are committed.

Parameters:
eventRegistrationCallback - The callback to notify when an Event is registered.


Copyright © 2010-2016. All Rights Reserved.