Class MessageDecorator<T>

java.lang.Object
org.axonframework.messaging.MessageDecorator<T>
All Implemented Interfaces:
Serializable, Message<T>
Direct Known Subclasses:
GenericCommandMessage, GenericEventMessage, GenericQueryMessage, GenericResetContext, GenericResultMessage

public abstract class MessageDecorator<T> extends Object implements Message<T>
Abstract implementation of a Message that delegates to an existing message. Extend this decorator class to extend the message with additional features.
Author:
Rene de Waele
See Also:
  • Constructor Details

    • MessageDecorator

      protected MessageDecorator(Message<T> delegate)
      Initializes a new decorator with given delegate message. The decorator delegates to the delegate for the message's payload, metadata and identifier.
      Parameters:
      delegate - the message delegate
  • Method Details

    • 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 message. 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 message
    • getPayload

      public T getPayload()
      Description copied from interface: Message
      Returns the payload of this message. The payload is the application-specific information.
      Specified by:
      getPayload in interface Message<T>
      Returns:
      the payload of this message
    • getPayloadType

      public Class<T> 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.
    • serializePayload

      public <S> SerializedObject<S> serializePayload(Serializer serializer, Class<S> expectedRepresentation)
      Description copied from interface: Message
      Serialize the payload of this message to the expectedRepresentation using given serializer. This method should return the same SerializedObject instance when invoked multiple times using the same serializer.
      Specified by:
      serializePayload in interface Message<T>
      Type Parameters:
      S - The type of the serialized data
      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 <S> SerializedObject<S> serializeMetaData(Serializer serializer, Class<S> expectedRepresentation)
      Description copied from interface: Message
      Serialize the meta data of this message to the expectedRepresentation using given serializer. This method should return the same SerializedObject instance when invoked multiple times using the same serializer.
      Specified by:
      serializeMetaData in interface Message<T>
      Type Parameters:
      S - The type of the serialized data
      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
    • getDelegate

      protected Message<T> getDelegate()
      Returns the wrapped message delegate.
      Returns:
      the delegate message
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • describeTo

      protected void describeTo(StringBuilder stringBuilder)
      Describe the message specific properties to the given stringBuilder. Subclasses should override this method, calling the super method and appending their own properties to the end (or beginning).

      As convention, String values should be enclosed in single quotes, Objects in curly brackets and numeric values may be appended without enclosing. All properties should be preceded by a comma when appending, or finish with a comma when prefixing values.

      Parameters:
      stringBuilder - the builder to append data to
    • describeType

      protected String describeType()
      Describe the type of message, used in toString().

      Defaults to the simple class name of the actual instance.

      Returns:
      the type of message