org.axonframework.domain
Class DomainEvent

java.lang.Object
  extended by org.axonframework.domain.EventBase
      extended by org.axonframework.domain.DomainEvent
All Implemented Interfaces:
Serializable, Event
Direct Known Subclasses:
AggregateSnapshot

public abstract class DomainEvent
extends EventBase

Base class for all Domain Events. This class contains the basic behavior expected from any event to be processed by event sourcing engines and aggregates.

Since:
0.1
Author:
Allard Buijze
See Also:
Serialized Form

Constructor Summary
protected DomainEvent()
          Initialize the domain event.
protected DomainEvent(long sequenceNumber, AggregateIdentifier aggregateIdentifier)
          Initialize the domain event.
 
Method Summary
 boolean equals(Object o)
          Checks for equality of two events.
 AggregateIdentifier getAggregateIdentifier()
          Returns the identifier of the aggregate that reported this event.
 Long getAggregateVersion()
          Returns the version number of the aggregate generating this event.
 Long getSequenceNumber()
          Returns the sequence number of this event, if available.
 int hashCode()
          
 
Methods inherited from class org.axonframework.domain.EventBase
addMetaData, getEventIdentifier, getEventRevision, getMetaData, getMetaDataValue, getTimestamp, setEventRevision
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DomainEvent

protected DomainEvent()
Initialize the domain event. Will set the current time stamp and generate a random event identifier. Use this constructor when using the AbstractEventSourcedAggregateRoot.apply(DomainEvent) method. The sequenceNumber and aggregateIdentifier are automatically set to the correct values for that aggregate.

If you do not use the AbstractEventSourcedAggregateRoot.apply(DomainEvent) method, but need the sequenceNumber and aggregateIdentifier to be set to specific values, use the DomainEvent(long, AggregateIdentifier) constructor.


DomainEvent

protected DomainEvent(long sequenceNumber,
                      AggregateIdentifier aggregateIdentifier)
Initialize the domain event. Will set the current time stamp and generate a random event identifier. Use this constructor when you need the sequenceNumber and aggregateIdentifier to be set to specific values.

Two use cases for this constructor are

When creating a DomainEvent using this constructor, all calls to setAggregateIdentifier(AggregateIdentifier) and setSequenceNumber(long) will result in an exception.

Parameters:
sequenceNumber - The sequence number to assign to this event
aggregateIdentifier - The identifier of the aggregate this event applies to
Method Detail

getSequenceNumber

public Long getSequenceNumber()
Returns the sequence number of this event, if available. Will return null if this event has not been added to an EventContainer.

Returns:
the sequence number of this event, or null if unknown.

getAggregateVersion

public Long getAggregateVersion()
Returns the version number of the aggregate generating this event. This method returns the same value as getSequenceNumber() and is solely provided to provide a clear meaning to the returned value.

Returns:
the version number of the aggregate generating this event.

getAggregateIdentifier

public AggregateIdentifier getAggregateIdentifier()
Returns the identifier of the aggregate that reported this event.

Returns:
the identifier of the aggregate that reported this event

equals

public boolean equals(Object o)
Checks for equality of two events. Two events are equal when they have the same type, aggregate identifier, time stamp and sequence number. This allows to test for equality after one or more instances have been serialized and deserialized.

Overrides:
equals in class EventBase
Parameters:
o - the other DomainEvent
Returns:
true when equals, otherwise false

hashCode

public int hashCode()

Overrides:
hashCode in class EventBase


Copyright © 2011. All Rights Reserved.