Class GenericEventMessage<T>

java.lang.Object
org.axonframework.messaging.MessageDecorator<T>
org.axonframework.eventhandling.GenericEventMessage<T>
Type Parameters:
T - The type of payload contained in this Message
All Implemented Interfaces:
Serializable, EventMessage<T>, Message<T>
Direct Known Subclasses:
GenericDeadlineMessage, GenericDomainEventMessage, GenericTrackedEventMessage

public class GenericEventMessage<T> extends MessageDecorator<T> implements EventMessage<T>
Generic implementation of the EventMessage interface.
See Also:
  • Field Details

    • clock

      public static Clock clock
      Clock instance used to set the time on new events. To fix the time while testing set this value to a constant value.
  • Constructor Details

    • GenericEventMessage

      public GenericEventMessage(T payload)
      Creates a GenericEventMessage with given payload, and an empty MetaData.
      Parameters:
      payload - The payload for the message
      See Also:
    • GenericEventMessage

      public GenericEventMessage(T payload, @Nonnull Map<String,?> metaData)
      Creates a GenericEventMessage with given payload and given metaData.
      Parameters:
      payload - The payload of the EventMessage
      metaData - The MetaData for the EventMessage
      See Also:
    • GenericEventMessage

      public GenericEventMessage(@Nonnull String identifier, T payload, @Nonnull Map<String,?> metaData, @Nonnull Instant timestamp)
      Constructor to reconstruct an EventMessage using existing data.
      Parameters:
      identifier - The identifier of the Message
      payload - The payload of the message
      metaData - The metadata of the message
      timestamp - The timestamp of the Message creation
    • GenericEventMessage

      public GenericEventMessage(@Nonnull Message<T> delegate, @Nonnull Supplier<Instant> timestampSupplier)
      Constructor to reconstruct an EventMessage using existing data. The timestamp of the event is supplied lazily to prevent unnecessary deserialization of the timestamp.
      Parameters:
      delegate - The message containing payload, identifier and metadata
      timestampSupplier - Supplier for the timestamp of the Message creation
    • GenericEventMessage

      protected GenericEventMessage(@Nonnull Message<T> delegate, @Nonnull Instant timestamp)
      Initializes a GenericEventMessage with given message as delegate and given timestamp. The given message will be used supply the payload, metadata and identifier of the resulting event message.
      Parameters:
      delegate - the message that will be used as delegate
      timestamp - the timestamp of the resulting event message
  • Method Details

    • asEventMessage

      public static <T> EventMessage<T> asEventMessage(@Nonnull Object event)
      Returns the given event as an EventMessage. If event already implements EventMessage, it is returned as-is. If it is a Message, a new EventMessage will be created using the payload and meta data of the given message. Otherwise, the given event is wrapped into a GenericEventMessage as its payload.
      Type Parameters:
      T - The generic type of the expected payload of the resulting object
      Parameters:
      event - the event to wrap as EventMessage
      Returns:
      an EventMessage containing given event as payload, or event if it already implements EventMessage.
    • getTimestamp

      @Nonnull public Instant getTimestamp()
      Description copied from interface: EventMessage
      Returns the timestamp of this event. The timestamp is set to the date and time the event was reported.
      Specified by:
      getTimestamp in interface EventMessage<T>
      Returns:
      the timestamp of this event.
    • withMetaData

      public GenericEventMessage<T> withMetaData(@Nonnull Map<String,?> metaData)
      Description copied from interface: EventMessage
      Returns a copy of this EventMessage with the given metaData. The payload, Timestamp and Identifier remain unchanged.
      Specified by:
      withMetaData in interface EventMessage<T>
      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 GenericEventMessage<T> andMetaData(@Nonnull Map<String,?> metaData)
      Description copied from interface: EventMessage
      Returns a copy of this EventMessage with it MetaData merged with the given metaData. The payload, Timestamp and Identifier remain unchanged.
      Specified by:
      andMetaData in interface EventMessage<T>
      Specified by:
      andMetaData in interface Message<T>
      Parameters:
      metaData - The MetaData to merge with
      Returns:
      a copy of this message with the given MetaData
    • describeTo

      protected void describeTo(StringBuilder stringBuilder)
      Description copied from class: MessageDecorator
      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.

      Overrides:
      describeTo in class MessageDecorator<T>
      Parameters:
      stringBuilder - the builder to append data to
    • describeType

      protected String describeType()
      Description copied from class: MessageDecorator
      Describe the type of message, used in MessageDecorator.toString().

      Defaults to the simple class name of the actual instance.

      Overrides:
      describeType in class MessageDecorator<T>
      Returns:
      the type of message