org.axonframework.serializer
Class SerializedMessage<T>

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

public class SerializedMessage<T>
extends Object
implements Message<T>, SerializationAware

Message implementation that is optimized to cope with serialized Payload and MetaData. The Payload and MetaData will only be deserialized when requested.

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
SerializedMessage(String identifier, SerializedObject<?> serializedPayload, SerializedObject<?> serializedMetaData, Serializer serializer)
          Reconstructs a Message using the given identifier, serializedPayload, serializedMetaData and serializer.
 
Method Summary
 SerializedMessage<T> andMetaData(Map<String,?> metaData)
          Returns a copy of this Message with it MetaData merged with the given metaData.
 String getIdentifier()
          Returns the identifier of this message.
 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.
 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.
 SerializedMessage<T> withMetaData(Map<String,?> metaData)
          Returns a copy of this Message 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

SerializedMessage

public SerializedMessage(String identifier,
                         SerializedObject<?> serializedPayload,
                         SerializedObject<?> serializedMetaData,
                         Serializer serializer)
Reconstructs a Message using the given identifier, serializedPayload, serializedMetaData and serializer.

Parameters:
identifier - The identifier of the 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: Message
Returns the identifier of this message. Two messages with the same identifiers should be interpreted as different representations of the same conceptual message. In such case, the meta-data may be different for both representations. The payload may be identical.

Specified by:
getIdentifier in interface Message<T>
Returns:
the unique identifier of this message

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 SerializedMessage<T> withMetaData(Map<String,?> metaData)
Description copied from interface: Message
Returns a copy of this Message with the given metaData. The payload remains unchanged.

While the implementation returned may be different than the implementation of this, implementations must take special care in returning the same type of Message (e.g. EventMessage, DomainEventMessage) to prevent errors further downstream.

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

Specified by:
andMetaData in interface Message<T>
Parameters:
metaData - 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 GenericMessage to use as a replacement when serializing


Copyright © 2010-2016. All Rights Reserved.