public class GenericMessage<T> extends AbstractMessage<T>
Message
that contains the payload and metadata as unserialized values.
If a GenericMessage is created while a UnitOfWork
is active it copies
over the correlation data of the UnitOfWork to the created message.
Constructor and Description |
---|
GenericMessage(Class<T> declaredPayloadType,
T payload,
Map<String,?> metaData)
Constructs a Message for the given
payload and meta data . |
GenericMessage(String identifier,
Class<T> declaredPayloadType,
T payload,
Map<String,?> metaData)
Constructor to reconstruct a Message using existing data.
|
GenericMessage(String identifier,
T payload,
Map<String,?> metaData)
Constructor to reconstruct a Message using existing data.
|
GenericMessage(T payload)
Constructs a Message for the given
payload using the correlation data of the current Unit of Work, if
present. |
GenericMessage(T payload,
Map<String,?> metaData)
Constructs a Message for the given
payload and meta data . |
Modifier and Type | Method and Description |
---|---|
static Message<?> |
asMessage(Object payloadOrMessage)
Returns a Message representing the given
payloadOrMessage , either by wrapping it or by returning it
as-is. |
MetaData |
getMetaData()
Returns the meta data for this event.
|
T |
getPayload()
Returns the payload of this Event.
|
Class<T> |
getPayloadType()
Returns the type of the payload.
|
<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 . |
protected Message<T> |
withMetaData(MetaData metaData)
Returns a new message instance with the same payload and properties as this message but given
metaData . |
andMetaData, getIdentifier, withMetaData
public GenericMessage(T payload)
payload
using the correlation data of the current Unit of Work, if
present.payload
- The payload for the messagepublic GenericMessage(T payload, Map<String,?> metaData)
payload
and meta data
. The given metaData
is merged
with the MetaData from the correlation data of the current unit of work, if present. In case the payload
== null
, Void
will be used as the payloadType
.payload
- The payload for the message as a generic T
metaData
- The meta data Map
for the messagepublic GenericMessage(Class<T> declaredPayloadType, T payload, Map<String,?> metaData)
payload
and meta data
. The given metaData
is merged
with the MetaData from the correlation data of the current unit of work, if present.declaredPayloadType
- The declared type of message payloadpayload
- The payload for the messagemetaData
- The meta data for the messagepublic GenericMessage(String identifier, T payload, Map<String,?> metaData)
GenericMessage(Object,
Map)
instead.identifier
- The identifier of the Messagepayload
- The payload of the messagemetaData
- The meta data of the messageNullPointerException
- when the given payload
is null
.public GenericMessage(String identifier, Class<T> declaredPayloadType, T payload, Map<String,?> metaData)
GenericMessage(Object,
Map)
insteadidentifier
- The identifier of the MessagedeclaredPayloadType
- The declared type of message payloadpayload
- The payload for the messagemetaData
- The meta data for the messagepublic static Message<?> asMessage(Object payloadOrMessage)
payloadOrMessage
, either by wrapping it or by returning it
as-is. If the given payloadOrMessage
already implements Message
, it is returned as-is, otherwise
a Message
is returned with the parameter as its payload.payloadOrMessage
- The payload to wrap or message to returnpublic MetaData getMetaData()
Message
public T getPayload()
Message
public Class<T> getPayloadType()
Message
getPayload().getClass()
, but allows implementations to optimize by using
lazy loading or deserialization.protected Message<T> withMetaData(MetaData metaData)
AbstractMessage
metaData
.withMetaData
in class AbstractMessage<T>
metaData
- The metadata in the new messagepublic <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 toCopyright © 2010–2020. All rights reserved.