org.axonframework.serializer
Class SerializationAwareEventMessage<T>

java.lang.Object
  extended by org.axonframework.serializer.SerializationAwareEventMessage<T>
Type Parameters:
T - The payload type of the Message
All Implemented Interfaces:
Serializable, EventMessage<T>, Message<T>, SerializationAware
Direct Known Subclasses:
SerializationAwareDomainEventMessage

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

Wrapper around am EventMessage that adds "Serialization Awareness" to the message it wraps. This implementation ensures that, when the payload or meta data is being serialized more than once using the same serializer, only a single serialization will actually occur. Subsequent invocations will return the same SerializedObject instance as the first.

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

Constructor Summary
protected SerializationAwareEventMessage(EventMessage<T> eventMessage)
          Initializes a new wrapper for the given eventMessage.
 
Method Summary
 EventMessage<T> andMetaData(Map<String,?> metaData)
          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.
<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.
 EventMessage<T> withMetaData(Map<String,?> metaData)
          Returns a copy of this EventMessage with the given metaData.
static
<T> EventMessage<T>
wrap(EventMessage<T> message)
          Wrap the given message to make it SerializationAware.
protected  Object writeReplace()
          Replacement function for Java Serialization API.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerializationAwareEventMessage

protected SerializationAwareEventMessage(EventMessage<T> eventMessage)
Initializes a new wrapper for the given eventMessage.

Parameters:
eventMessage - The message to wrap
Method Detail

wrap

public static <T> EventMessage<T> wrap(EventMessage<T> message)
Wrap the given message to make it SerializationAware. The returning object can be safely cast to SerializationAware. If the given message already implements SerializationAware, it is returned as-is. It is therefore not safe to assume the returning message is an instance of SerializationAwareEventMessage.

Type Parameters:
T - The payload type of the message
Parameters:
message - The message to wrap
Returns:
a serialization aware version of the given message

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.

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.

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.

withMetaData

public EventMessage<T> withMetaData(Map<String,?> metaData)
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:
metaData - The new MetaData for the Message
Returns:
a copy of this message with the given MetaData

andMetaData

public EventMessage<T> andMetaData(Map<String,?> metaData)
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:
metaData - The MetaData to merge with
Returns:
a copy of this message with the given MetaData

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

writeReplace

protected Object writeReplace()
Replacement function for Java Serialization API. When this object is serialized, it is replaced by the implementation it wraps.

Returns:
the EventMessage wrapped by this message


Copyright © 2010-2016. All Rights Reserved.