org.axonframework.serializer
Class SerializedEventMessage<T>

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

public class SerializedEventMessage<T>
extends Object
implements EventMessage<T>, SerializationAware

EventMessage 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
See Also:
Serialized Form

Constructor Summary
SerializedEventMessage(String eventIdentifier, org.joda.time.DateTime timestamp, SerializedObject<?> serializedPayload, SerializedObject<?> serializedMetaData, Serializer serializer)
          Constructor to reconstruct an EventMessage using serialized data
 
Method Summary
 EventMessage<T> andMetaData(Map<String,?> additionalMetaData)
          Returns a copy of this EventMessage with it MetaData merged with the given metaData.
 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.
 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.
 SerializedEventMessage<T> withMetaData(Map<String,?> newMetaData)
          Returns a copy of this EventMessage 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

SerializedEventMessage

public SerializedEventMessage(String eventIdentifier,
                              org.joda.time.DateTime timestamp,
                              SerializedObject<?> serializedPayload,
                              SerializedObject<?> serializedMetaData,
                              Serializer serializer)
Constructor to reconstruct an EventMessage using serialized data

Parameters:
eventIdentifier - The identifier of the message
timestamp - The timestamp of the event message
serializedPayload - The serialized payload of the message
serializedMetaData - The serialized meta data of the message
serializer - The serializer to deserialize the payload and meta data with
Throws:
UnknownSerializedTypeException - if the type of the serialized object cannot be resolved to a class
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

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.

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.

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

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

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.

withMetaData

public SerializedEventMessage<T> withMetaData(Map<String,?> newMetaData)
Description copied from interface: EventMessage
Returns a copy of this EventMessage with the given metaData. The payload, Timestamp and Identifier remain unchanged.

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 EventMessage<T> andMetaData(Map<String,?> additionalMetaData)
Description copied from interface: EventMessage
Returns a copy of this EventMessage with it MetaData merged with the given metaData. The payload, Timestamp and Identifier remain unchanged.

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

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 GenericEventMessage to use as a replacement when serializing


Copyright © 2010-2016. All Rights Reserved.