public class SerializedMessage<T> extends AbstractMessage<T>
getPayload()
or getMetaData()
is called.
The SerializedMessage guarantees that the payload and metadata will not be deserialized more than once. Messages of this type will not be serialized more than once by the same serializer.
Constructor and Description |
---|
SerializedMessage(String identifier,
LazyDeserializingObject<T> payload,
LazyDeserializingObject<MetaData> metaData)
Initializes a
SerializedMessage with given identifier from the given lazily deserializing payload
and metadata. |
SerializedMessage(String identifier,
SerializedObject<?> serializedPayload,
SerializedObject<?> serializedMetaData,
Serializer serializer)
Initializes a
SerializedMessage with given identifier from the given serialized payload and
metadata. |
Modifier and Type | Method and Description |
---|---|
SerializedMessage<T> |
andMetaData(Map<String,?> metaData)
Returns a copy of this Message with it MetaData merged with the given
metaData . |
MetaData |
getMetaData()
Returns the meta data for this message.
|
T |
getPayload()
Returns the payload of this message.
|
Class<T> |
getPayloadType()
Returns the type of the payload.
|
boolean |
isMetaDataDeserialized()
Indicates whether the metaData of this message has already been deserialized.
|
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 to the
expectedRepresentation using given serializer . |
<R> SerializedObject<R> |
serializePayload(Serializer serializer,
Class<R> expectedRepresentation)
Serialize the payload of this message to the
expectedRepresentation using given serializer . |
SerializedMessage<T> |
withMetaData(Map<String,?> metaData)
Returns a copy of this Message with the given
metaData . |
protected SerializedMessage<T> |
withMetaData(MetaData metaData)
Returns a new message instance with the same payload and properties as this message but 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.
|
getIdentifier
public SerializedMessage(String identifier, SerializedObject<?> serializedPayload, SerializedObject<?> serializedMetaData, Serializer serializer)
SerializedMessage
with given identifier
from the given serialized payload and
metadata. The given serializer
will be used to deserialize the data.identifier
- the message identifierserializedPayload
- the serialized message payloadserializedMetaData
- the serialized message metadataserializer
- the serializer required when the data needs to be deserializedpublic SerializedMessage(String identifier, LazyDeserializingObject<T> payload, LazyDeserializingObject<MetaData> metaData)
SerializedMessage
with given identifier
from the given lazily deserializing payload
and metadata.identifier
- the message identifierpayload
- serialized payload that can be deserialized on demand and never more than oncemetaData
- serialized metadata that can be deserialized on demand and never more than oncepublic T getPayload()
Message
public MetaData getMetaData()
Message
public Class<T> getPayloadType()
Message
getPayload().getClass()
, but allows implementations to optimize by using lazy
loading or deserialization.protected SerializedMessage<T> withMetaData(MetaData metaData)
AbstractMessage
metaData
.withMetaData
in class AbstractMessage<T>
metaData
- The metadata in the new messagepublic SerializedMessage<T> withMetaData(@Nonnull Map<String,?> metaData)
Message
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.withMetaData
in interface Message<T>
withMetaData
in class AbstractMessage<T>
metaData
- The new MetaData for the Messagepublic SerializedMessage<T> andMetaData(@Nonnull Map<String,?> metaData)
Message
metaData
. The payload remains
unchanged.andMetaData
in interface Message<T>
andMetaData
in class AbstractMessage<T>
metaData
- The MetaData to merge withpublic <R> SerializedObject<R> serializePayload(Serializer serializer, Class<R> expectedRepresentation)
Message
expectedRepresentation
using given serializer
. This
method should return the same SerializedObject instance when invoked multiple times using the same
serializer.R
- The type of the serialized dataserializer
- The serializer to serialize payload withexpectedRepresentation
- The type of data to serialize topublic <R> SerializedObject<R> serializeMetaData(Serializer serializer, Class<R> expectedRepresentation)
Message
expectedRepresentation
using given serializer
.
This method should return the same SerializedObject instance when invoked multiple times using the same
serializer.R
- The type of the serialized dataserializer
- The serializer to serialize meta data withexpectedRepresentation
- The type of data to serialize topublic boolean isPayloadDeserialized()
true
if the payload is deserialized, otherwise false
public boolean isMetaDataDeserialized()
true
if the metaData is deserialized, otherwise false
protected Object writeReplace()
Copyright © 2010–2024. All rights reserved.