org.axonframework.domain
Class GenericEventMessage<T>

java.lang.Object
  extended by org.axonframework.domain.GenericMessage<T>
      extended by org.axonframework.domain.GenericEventMessage<T>
Type Parameters:
T - The type of payload contained in this Message
All Implemented Interfaces:
Serializable, EventMessage<T>, Message<T>
Direct Known Subclasses:
GenericDomainEventMessage

public class GenericEventMessage<T>
extends GenericMessage<T>
implements EventMessage<T>

Generic implementation of the EventMessage interface. It simply keeps a reference to the payload and MetaData.

Since:
2.0
Author:
Allard Buijze
See Also:
Serialized Form

Constructor Summary
GenericEventMessage(String identifier, org.joda.time.DateTime timestamp, T payload, Map<String,?> metaData)
          Constructor to reconstruct an EventMessage using existing data.
GenericEventMessage(T payload)
          Creates a GenericEventMessage with given payload, and an empty MetaData.
GenericEventMessage(T payload, Map<String,?> metaData)
          Creates a GenericEventMessage with given payload and given metaData.
 
Method Summary
 GenericEventMessage<T> andMetaData(Map<String,?> additionalMetaData)
          Returns a copy of this Message with it MetaData merged with the given metaData.
static
<T> EventMessage<T>
asEventMessage(Object event)
          Returns the given event as an EventMessage.
 org.joda.time.DateTime getTimestamp()
          Returns the timestamp of this event.
 String toString()
           
 GenericEventMessage<T> withMetaData(Map<String,?> newMetaData)
          Returns a copy of this Message with the given metaData.
 
Methods inherited from class org.axonframework.domain.GenericMessage
getIdentifier, getMetaData, getPayload, getPayloadType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.axonframework.domain.EventMessage
getIdentifier
 
Methods inherited from interface org.axonframework.domain.Message
getMetaData, getPayload, getPayloadType
 

Constructor Detail

GenericEventMessage

public GenericEventMessage(T payload)
Creates a GenericEventMessage with given payload, and an empty MetaData.

Parameters:
payload - The payload for the message
See Also:
asEventMessage(Object)

GenericEventMessage

public GenericEventMessage(T payload,
                           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:
asEventMessage(Object)

GenericEventMessage

public GenericEventMessage(String identifier,
                           org.joda.time.DateTime timestamp,
                           T payload,
                           Map<String,?> metaData)
Constructor to reconstruct an EventMessage using existing data.

Parameters:
identifier - The identifier of the Message
timestamp - The timestamp of the Message creation
payload - The payload of the message
metaData - The meta data of the message
Method Detail

asEventMessage

public static <T> EventMessage<T> asEventMessage(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

public org.joda.time.DateTime 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(Map<String,?> newMetaData)
Description copied from interface: Message
Returns a copy of this Message with the given metaData. The payload remains unchanged.

While the implementation returned may be different than the implementation of this, implementations must take special care in returning the same type of Message (e.g. EventMessage, DomainEventMessage) to prevent errors further downstream.

Specified by:
withMetaData in interface EventMessage<T>
Specified by:
withMetaData in interface Message<T>
Overrides:
withMetaData in class GenericMessage<T>
Parameters:
newMetaData - The new MetaData for the Message
Returns:
a copy of this message with the given MetaData

andMetaData

public GenericEventMessage<T> andMetaData(Map<String,?> additionalMetaData)
Description copied from interface: Message
Returns a copy of this Message with it MetaData merged with the given metaData. The payload remains unchanged.

Specified by:
andMetaData in interface EventMessage<T>
Specified by:
andMetaData in interface Message<T>
Overrides:
andMetaData in class GenericMessage<T>
Parameters:
additionalMetaData - The MetaData to merge with
Returns:
a copy of this message with the given MetaData

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2010-2016. All Rights Reserved.