org.axonframework.serializer
Class SerializedDomainEventMessage<T>

java.lang.Object
  extended by org.axonframework.serializer.SerializedDomainEventMessage<T>
Type Parameters:
T - The type of payload contained in this message
All Implemented Interfaces:
Serializable, DomainEventMessage<T>, EventMessage<T>, Message<T>, SerializationAware

public class SerializedDomainEventMessage<T>
extends Object
implements DomainEventMessage<T>, SerializationAware

DomainEventMessage implementation that is optimized to cope with serialized Payload and MetaData. The Payload and MetaData will only be deserialized when requested. This means that loaded event for which there is no handler will never be deserialized.

This implementation is Serializable as per Java specification. Both MetaData and Payload are deserialized prior to being written to the OutputStream.

Since:
2.0
Author:
Allard Buijze, Frank Versnel
See Also:
Serialized Form

Constructor Summary
SerializedDomainEventMessage(SerializedDomainEventData domainEventData, Serializer serializer)
          Reconstructs a DomainEventMessage using the given domainEventData, containing data to be deserialized using the given serializer.
SerializedDomainEventMessage(SerializedEventMessage<T> eventMessage, Object aggregateIdentifier, long sequenceNumber)
          Wrapper constructor for wrapping a SerializedEventMessage as a SerializedDomainEventMessage, using given aggregateIdentifier and sequenceNumber.
 
Method Summary
 DomainEventMessage<T> andMetaData(Map<String,?> additionalMetaData)
          Returns a copy of this DomainEventMessage with its MetaData merged with the given metaData.
 Object getAggregateIdentifier()
          Returns the identifier of the Aggregate that generated this DomainEvent.
 String getIdentifier()
          Returns the identifier of this event.
 MetaData getMetaData()
          Returns the meta data for this event.
 T getPayload()
          Returns the payload of this Event.
 Class getPayloadType()
          Returns the type of the payload.
 long getSequenceNumber()
          Returns the sequence number that allows DomainEvents originating from the same Aggregate to be placed in the order of generation.
 org.joda.time.DateTime getTimestamp()
          Returns the timestamp of this event.
 boolean isPayloadDeserialized()
          Indicates whether the payload of this message has already been deserialized.
<R> SerializedObject<R>
serializeMetaData(Serializer serializer, Class<R> expectedRepresentation)
          Serialize the meta data of this message using given serializer, using given expectedRepresentation.
<R> SerializedObject<R>
serializePayload(Serializer serializer, Class<R> expectedRepresentation)
          Serialize the payload of this message using given serializer, using given expectedRepresentation.
 DomainEventMessage<T> withMetaData(Map<String,?> newMetaData)
          Returns a copy of this DomainEventMessage with the given metaData.
protected  Object writeReplace()
          Java Serialization API Method that provides a replacement to serialize, as the fields contained in this instance are not serializable themselves.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerializedDomainEventMessage

public SerializedDomainEventMessage(SerializedDomainEventData domainEventData,
                                    Serializer serializer)
Reconstructs a DomainEventMessage using the given domainEventData, containing data to be deserialized using the given serializer. The serialized data is deserialized on-demand.

Parameters:
domainEventData - The SerializedDomainEventData providing access to this message's data
serializer - The Serializer to deserialize the meta data and payload with

SerializedDomainEventMessage

public SerializedDomainEventMessage(SerializedEventMessage<T> eventMessage,
                                    Object aggregateIdentifier,
                                    long sequenceNumber)
Wrapper constructor for wrapping a SerializedEventMessage as a SerializedDomainEventMessage, using given aggregateIdentifier and sequenceNumber. This constructor should be used to reconstruct an instance of an existing serialized Domain Event Message

Parameters:
eventMessage - The eventMessage to wrap
aggregateIdentifier - The identifier of the aggregate that generated the message
sequenceNumber - The sequence number of the generated event
Method Detail

serializePayload

public <R> SerializedObject<R> serializePayload(Serializer serializer,
                                                Class<R> expectedRepresentation)
Description copied from interface: SerializationAware
Serialize the payload of this message using given serializer, using given expectedRepresentation. This method should return the same SerializedObject instance when invoked multiple times using the same serializer.

Specified by:
serializePayload in interface SerializationAware
Type Parameters:
R - The type of data to serialize to
Parameters:
serializer - The serializer to serialize payload with
expectedRepresentation - The type of data to serialize to
Returns:
a SerializedObject containing the serialized representation of the message's payload

serializeMetaData

public <R> SerializedObject<R> serializeMetaData(Serializer serializer,
                                                 Class<R> expectedRepresentation)
Description copied from interface: SerializationAware
Serialize the meta data of this message using given serializer, using given expectedRepresentation. This method should return the same SerializedObject instance when invoked multiple times using the same serializer.

Specified by:
serializeMetaData in interface SerializationAware
Type Parameters:
R - The type of data to serialize to
Parameters:
serializer - The serializer to serialize meta data with
expectedRepresentation - The type of data to serialize to
Returns:
a SerializedObject containing the serialized representation of the message's meta data

getSequenceNumber

public long getSequenceNumber()
Description copied from interface: DomainEventMessage
Returns the sequence number that allows DomainEvents originating from the same Aggregate to be placed in the order of generation.

Specified by:
getSequenceNumber in interface DomainEventMessage<T>
Returns:
the sequence number of this Event

getAggregateIdentifier

public Object getAggregateIdentifier()
Description copied from interface: DomainEventMessage
Returns the identifier of the Aggregate that generated this DomainEvent. Note that the value returned does not necessarily have to be the same instance that was provided at creation time. It is possible that (due to serialization, for example) the value returned here has a different structure.

Specified by:
getAggregateIdentifier in interface DomainEventMessage<T>
Returns:
the identifier of the Aggregate that generated this DomainEvent

withMetaData

public DomainEventMessage<T> withMetaData(Map<String,?> newMetaData)
Description copied from interface: DomainEventMessage
Returns a copy of this DomainEventMessage with the given metaData. The payload, Timestamp and EventIdentifier, as well as the Aggregate Identifier and Sequence Number remain unchanged.

Specified by:
withMetaData in interface DomainEventMessage<T>
Specified by:
withMetaData in interface EventMessage<T>
Specified by:
withMetaData in interface Message<T>
Parameters:
newMetaData - The new MetaData for the Message
Returns:
a copy of this message with the given MetaData

andMetaData

public DomainEventMessage<T> andMetaData(Map<String,?> additionalMetaData)
Returns a copy of this DomainEventMessage with its MetaData merged with the given metaData. The payload, Timestamp and EventIdentifier, as well as the Aggregate Identifier and Sequence Number remain unchanged.

This method will force the MetaData to be deserialized if not already done.

Specified by:
andMetaData in interface DomainEventMessage<T>
Specified by:
andMetaData in interface EventMessage<T>
Specified by:
andMetaData in interface Message<T>
Parameters:
additionalMetaData - The MetaData to merge with
Returns:
a copy of this message with the given MetaData

getPayloadType

public Class getPayloadType()
Description copied from interface: Message
Returns the type of the payload.

Is semantically equal to getPayload().getClass(), but allows implementations to optimize by using lazy loading or deserialization.

Specified by:
getPayloadType in interface Message<T>
Returns:
the type of payload.

getPayload

public T getPayload()
Description copied from interface: Message
Returns the payload of this Event. The payload is the application-specific information.

Specified by:
getPayload in interface Message<T>
Returns:
the payload of this Event

getMetaData

public MetaData getMetaData()
Description copied from interface: Message
Returns the meta data for this event. This meta data is a collection of key-value pairs, where the key is a String, and the value is a serializable object.

Specified by:
getMetaData in interface Message<T>
Returns:
the meta data for this event

getTimestamp

public org.joda.time.DateTime getTimestamp()
Description copied from interface: EventMessage
Returns the timestamp of this event. The timestamp is set to the date and time the event was reported.

Specified by:
getTimestamp in interface EventMessage<T>
Returns:
the timestamp of this event.

getIdentifier

public String getIdentifier()
Description copied from interface: EventMessage
Returns the identifier of this event. The identifier is used to define the uniqueness of an event. Two events may contain similar (or equal) payload and timestamp, if the EventIdentifiers are different, they both represent a different occurrence of an Event. If two messages have the same identifier, they both represent the same unique occurrence of an event, even though the resulting view may be different. You may not assume two messages are equal (i.e. interchangeable) if their identifier is equal.

For example, an AddressChangeEvent may occur twice for the same Event, because someone moved back to the previous address. In that case, the Event payload is equal for both EventMessage instances, but the Event Identifier is different for both.

Specified by:
getIdentifier in interface EventMessage<T>
Specified by:
getIdentifier in interface Message<T>
Returns:
the identifier of this event.

isPayloadDeserialized

public boolean isPayloadDeserialized()
Indicates whether the payload of this message has already been deserialized.

Returns:
true if the payload is deserialized, otherwise false

writeReplace

protected Object writeReplace()
Java Serialization API Method that provides a replacement to serialize, as the fields contained in this instance are not serializable themselves.

Returns:
the GenericDomainEventMessage to use as a replacement when serializing


Copyright © 2010-2016. All Rights Reserved.