Package org.axonframework.eventhandling
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
Generic implementation of the EventMessage interface.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionConstructor to reconstruct an EventMessage using existing data.protectedGenericEventMessage(Message<T> delegate, Instant timestamp) Initializes aGenericEventMessagewith given message as delegate and giventimestamp.GenericEventMessage(Message<T> delegate, Supplier<Instant> timestampSupplier) Constructor to reconstruct an EventMessage using existing data.GenericEventMessage(T payload) Creates a GenericEventMessage with givenpayload, and an empty MetaData.GenericEventMessage(T payload, Map<String, ?> metaData) Creates a GenericEventMessage with givenpayloadand givenmetaData. -
Method Summary
Modifier and TypeMethodDescriptionandMetaData(Map<String, ?> metaData) Returns a copy of this EventMessage with it MetaData merged with the givenmetaData.static <T> EventMessage<T> asEventMessage(Object event) Returns the given event as an EventMessage.protected voiddescribeTo(StringBuilder stringBuilder) Describe the message specific properties to the givenstringBuilder.protected StringDescribe the type of message, used inMessageDecorator.toString().Returns the timestamp of this event.withMetaData(Map<String, ?> metaData) Returns a copy of this EventMessage with the givenmetaData.Methods inherited from class org.axonframework.messaging.MessageDecorator
getDelegate, getIdentifier, getMetaData, getPayload, getPayloadType, serializeMetaData, serializePayload, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.axonframework.eventhandling.EventMessage
getIdentifierMethods inherited from interface org.axonframework.messaging.Message
getMetaData, getPayload, getPayloadType, serializeMetaData, serializePayload
-
Field Details
-
clock
Clockinstance used to set the time on new events. To fix the time while testing set this value to a constant value.
-
-
Constructor Details
-
GenericEventMessage
Creates a GenericEventMessage with givenpayload, and an empty MetaData.- Parameters:
payload- The payload for the message- See Also:
-
GenericEventMessage
Creates a GenericEventMessage with givenpayloadand givenmetaData.- Parameters:
payload- The payload of the EventMessagemetaData- 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 Messagepayload- The payload of the messagemetaData- The metadata of the messagetimestamp- 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 metadatatimestampSupplier- Supplier for the timestamp of the Message creation
-
GenericEventMessage
Initializes aGenericEventMessagewith given message as delegate and giventimestamp. 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 delegatetimestamp- the timestamp of the resulting event message
-
-
Method Details
-
asEventMessage
Returns the given event as an EventMessage. Ifeventalready 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 giveneventis 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
eventas payload, oreventif it already implements EventMessage.
-
getTimestamp
Description copied from interface:EventMessageReturns the timestamp of this event. The timestamp is set to the date and time the event was reported.- Specified by:
getTimestampin interfaceEventMessage<T>- Returns:
- the timestamp of this event.
-
withMetaData
Description copied from interface:EventMessageReturns a copy of this EventMessage with the givenmetaData. The payload,TimestampandIdentifierremain unchanged.- Specified by:
withMetaDatain interfaceEventMessage<T>- Specified by:
withMetaDatain interfaceMessage<T>- Parameters:
metaData- The new MetaData for the Message- Returns:
- a copy of this message with the given MetaData
-
andMetaData
Description copied from interface:EventMessageReturns a copy of this EventMessage with it MetaData merged with the givenmetaData. The payload,TimestampandIdentifierremain unchanged.- Specified by:
andMetaDatain interfaceEventMessage<T>- Specified by:
andMetaDatain interfaceMessage<T>- Parameters:
metaData- The MetaData to merge with- Returns:
- a copy of this message with the given MetaData
-
describeTo
Description copied from class:MessageDecoratorDescribe the message specific properties to the givenstringBuilder. 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:
describeToin classMessageDecorator<T>- Parameters:
stringBuilder- the builder to append data to
-
describeType
Description copied from class:MessageDecoratorDescribe the type of message, used inMessageDecorator.toString().Defaults to the simple class name of the actual instance.
- Overrides:
describeTypein classMessageDecorator<T>- Returns:
- the type of message
-