org.axonframework.domain
Class GenericMessage<T>

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

public class GenericMessage<T>
extends Object
implements Message<T>

Generic implementation of the Message interface.

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

Constructor Summary
GenericMessage(String identifier, T payload, Map<String,?> metaData)
          Constructor to reconstruct a Message using existing data.
GenericMessage(T payload)
          Constructs a Message for the given payload using empty meta data.
GenericMessage(T payload, Map<String,?> metaData)
          Constructs a Message for the given payload and meta data.
 
Method Summary
 GenericMessage<T> andMetaData(Map<String,?> additionalMetaData)
          Returns a copy of this Message with it MetaData merged with the given metaData.
 String getIdentifier()
          Returns the identifier of this message.
 MetaData getMetaData()
          Returns the meta data for this event.
 T getPayload()
          Returns the payload of this Event.
 Class getPayloadType()
          Returns the type of the payload.
 GenericMessage<T> withMetaData(Map<String,?> newMetaData)
          Returns a copy of this Message with the given metaData.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericMessage

public GenericMessage(T payload)
Constructs a Message for the given payload using empty meta data.

Parameters:
payload - The payload for the message

GenericMessage

public GenericMessage(T payload,
                      Map<String,?> metaData)
Constructs a Message for the given payload and meta data.

Parameters:
payload - The payload for the message
metaData - The meta data for the message

GenericMessage

public GenericMessage(String identifier,
                      T payload,
                      Map<String,?> metaData)
Constructor to reconstruct a Message using existing data.

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

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 event. 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 event

getPayload

public T getPayload()
Description copied from interface: Message
Returns the payload of this Event. The payload is the application-specific information.

Specified by:
getPayload in interface Message<T>
Returns:
the payload of this Event

getPayloadType

public Class 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.

withMetaData

public GenericMessage<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 Message<T>
Parameters:
newMetaData - The new MetaData for the Message
Returns:
a copy of this message with the given MetaData

andMetaData

public GenericMessage<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 Message<T>
Parameters:
additionalMetaData - The MetaData to merge with
Returns:
a copy of this message with the given MetaData


Copyright © 2010-2016. All Rights Reserved.