Class GenericMessage
- All Implemented Interfaces:
Message
Message interface containing the payload and
metadata in deserialized form.
This Message implementation is "conversion aware," as it is capable of maintaining a converter suitable for
its payload set via withConverter(Converter) and maintains any conversion results from
payloadAs(Type, Converter) and withConvertedPayload(Type, Converter) (either invoked with a
Class, TypeReference, or Type), together with the hash of the given Converter. In
doing so, this Message optimizes subsequent payloadAs/withConvertedPayload invocations for the same
type-and-converter combination. If this optimization should be disabled, the "AXON_CONVERSION_CACHE_ENABLED"
system property can be set to false.
- Since:
- 2.0.0
- Author:
- Allard Buijze, Steven van Beelen
-
Field Summary
Fields inherited from interface org.axonframework.messaging.core.Message
RESOURCE_KEY -
Constructor Summary
ConstructorsConstructorDescriptionGenericMessage(String identifier, MessageType type, @Nullable P payload, Class<P> declaredPayloadType, Map<String, String> metadata) Constructs aGenericMessagefor the givenidentifier,type,payload, andmetadata, intended to reconstruct anotherMessage.GenericMessage(String identifier, MessageType type, @Nullable Object payload, Map<String, String> metadata) Constructs aGenericMessagefor the givenidentifier,type,payload, andmetadata, intended to reconstruct anotherMessage.GenericMessage(MessageType type, @Nullable P payload, Class<P> declaredPayloadType, Map<String, String> metadata) Constructs aGenericMessagefor the giventype,payload,declaredPayloadType, andmetadata.GenericMessage(MessageType type, @Nullable Object payload) Constructs aGenericMessagefor the giventypeandpayload.GenericMessage(MessageType type, @Nullable Object payload, Map<String, String> metadata) Constructs aGenericMessagefor the giventype,payload, andmetadata. -
Method Summary
Modifier and TypeMethodDescriptionstatic MessageConstruct an empty message.metadata()Returns theMetadatafor thisMessage.@Nullable Objectpayload()Returns the payload of thisMessage.<T> @Nullable TReturns the payload of thisMessagecasted to the given type ifMessage.payloadType()isassignable fromthe giventype, otherwise throws aConversionException.<T> @Nullable TReturns the payload of thisMessage, converted to the giventypeby the givenconverter.Class<?> Returns the type of the payload.withConvertedPayload(Type type, Converter converter) Returns a newMessageimplementation with itsMessage.payload()converted to the giventypeby the givenconverter.withConverter(@Nullable Converter converter) Returns a newGenericMessageinstance with the same payload and properties as this message and the givenconverterto be used for payload conversion.protected MessagewithMetadata(Metadata metadata) Returns a new message instance with the same payload and properties as this message but givenmetadata.Methods inherited from class org.axonframework.messaging.core.AbstractMessage
andMetadata, identifier, type, withMetadataMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.core.Message
payloadAs, payloadAs, payloadAs, withConvertedPayload, withConvertedPayload
-
Constructor Details
-
GenericMessage
Constructs aGenericMessagefor the giventypeandpayload. -
GenericMessage
Constructs aGenericMessagefor the giventype,payload, andmetadata.In case the
payload == null,Voidwill be used as thepayloadType. -
GenericMessage
public GenericMessage(MessageType type, @Nullable P payload, Class<P> declaredPayloadType, Map<String, String> metadata) Constructs aGenericMessagefor the giventype,payload,declaredPayloadType, andmetadata. -
GenericMessage
public GenericMessage(String identifier, MessageType type, @Nullable Object payload, Map<String, String> metadata) Constructs aGenericMessagefor the givenidentifier,type,payload, andmetadata, intended to reconstruct anotherMessage. -
GenericMessage
public GenericMessage(String identifier, MessageType type, @Nullable P payload, Class<P> declaredPayloadType, Map<String, String> metadata) Constructs aGenericMessagefor the givenidentifier,type,payload, andmetadata, intended to reconstruct anotherMessage.- Type Parameters:
P- The generic type of the expected payload of the resulting object.- Parameters:
identifier- The identifier of thisMessage.type- Thetypefor thisMessage.payload- The payload of typePfor thisMessage.declaredPayloadType- The declared type of thepayloadof thisMessage.metadata- The metadata for thisMessage.
-
-
Method Details
-
emptyMessage
Construct an empty message.- Returns:
- A message with
nullMessage.payload(), noMetadata, and aMessage.type()of"empty".
-
payload
Description copied from interface:MessageReturns the payload of thisMessage.The payload is the application-specific information.
- Returns:
- The payload of this
Message.
-
payloadAs
Description copied from interface:MessageReturns the payload of thisMessagecasted to the given type ifMessage.payloadType()isassignable fromthe giventype, otherwise throws aConversionException.- Type Parameters:
T- The generic type to convert thisMessage'spayload to.- Parameters:
type- The type to convert thisMessage'spayload to.- Returns:
- The payload of this
Message, converted to the giventype.
-
payloadAs
Description copied from interface:MessageReturns the payload of thisMessage, converted to the giventypeby the givenconverter.If the given
typeis an instance ofClassandMessage.payloadType()isassignable fromthatClass,Message.payload()may be invoked instead of using the givenconverter.Implementers of this operation may optimize by storing the converted payloads, thus saving a
Converter.convert(Object, Class)invocation in the process. Only when this optimization is in place will anull converterresult in a successful invocation of this method.- Type Parameters:
T- The generic type to convert thisMessage'spayload to.- Parameters:
type- The type to convert thisMessage'spayload to.converter- The converter to convert thisMessage'spayload with.- Returns:
- The payload of this
Message, converted to the giventype.
-
payloadType
Description copied from interface:MessageReturns the type of the payload.Is semantically equal to
getPayload().getClass(), but allows implementations to optimize by using lazy loading or deserialization.- Returns:
- The type of payload.
-
metadata
Description copied from interface:MessageReturns theMetadatafor thisMessage.The
Metadatais a collection of key-value pairs, where both the key and values areStrings.- Returns:
- The
Metadatafor thisMessage.
-
withMetadata
Description copied from class:AbstractMessageReturns a new message instance with the same payload and properties as this message but givenmetadata.- Specified by:
withMetadatain classAbstractMessage- Parameters:
metadata- The metadata in the new message- Returns:
- a copy of this instance with given metadata
-
withConverter
Returns a newGenericMessageinstance with the same payload and properties as this message and the givenconverterto be used for payload conversion.Note: if called from a subtype, the message will lose subtype information because this method creates a new instance of
GenericMessage.- Parameters:
converter- the converter for the new message- Returns:
- a copy of this instance with the converter
-
withConvertedPayload
Description copied from interface:MessageReturns a newMessageimplementation with itsMessage.payload()converted to the giventypeby the givenconverter. This newMessageis effectively a copy ofthis Messagewith a renewed payload andMessage.payloadType().Will return the
thisinstance if thepayload typeisassignable fromthe converted result.- Parameters:
type- The type to convert theMessage.payload()to.converter- The converter to convert theMessage.payload()with.- Returns:
- A new
Messageimplementation with itsMessage.payload()converted to the giventypeby the givenconverter.
-