org.axonframework.commandhandling
Class GenericCommandMessage<T>

java.lang.Object
  extended by org.axonframework.commandhandling.GenericCommandMessage<T>
Type Parameters:
T - The type of payload contained in this Message
All Implemented Interfaces:
Serializable, CommandMessage<T>, Message<T>

public class GenericCommandMessage<T>
extends Object
implements CommandMessage<T>

Implementation of the CommandMessage that takes all properties as constructor parameters.

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

Constructor Summary
protected GenericCommandMessage(GenericCommandMessage<T> original, Map<String,?> metaData)
          Copy constructor that allows creation of a new GenericCommandMessage with modified metaData.
  GenericCommandMessage(String identifier, String commandName, T payload, Map<String,?> newMetaData)
          Create a CommandMessage with the given command as payload and a custom chosen identifier.
  GenericCommandMessage(String commandName, T payload, Map<String,?> newMetaData)
          Create a CommandMessage with the given command as payload.
  GenericCommandMessage(T payload)
          Create a CommandMessage with the given command as payload and empty metaData
  GenericCommandMessage(T payload, Map<String,?> newMetaData)
          Create a CommandMessage with the given command as payload.
 
Method Summary
 GenericCommandMessage<T> andMetaData(Map<String,?> additionalMetaData)
          Returns a copy of this CommandMessage with it MetaData merged with the given metaData.
static CommandMessage asCommandMessage(Object command)
          Returns the given command as a CommandMessage.
 String getCommandName()
          Returns the name of the command to execute.
 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.
 GenericCommandMessage<T> withMetaData(Map<String,?> newMetaData)
          Returns a copy of this CommandMessage with the given metaData.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericCommandMessage

public GenericCommandMessage(T payload)
Create a CommandMessage with the given command as payload and empty metaData

Parameters:
payload - the payload for the Message

GenericCommandMessage

public GenericCommandMessage(T payload,
                             Map<String,?> newMetaData)
Create a CommandMessage with the given command as payload.

Parameters:
payload - the payload for the Message
newMetaData - The meta data for this message

GenericCommandMessage

public GenericCommandMessage(String commandName,
                             T payload,
                             Map<String,?> newMetaData)
Create a CommandMessage with the given command as payload.

Parameters:
commandName - The name of the command
payload - the payload for the Message
newMetaData - The meta data for this message

GenericCommandMessage

public GenericCommandMessage(String identifier,
                             String commandName,
                             T payload,
                             Map<String,?> newMetaData)
Create a CommandMessage with the given command as payload and a custom chosen identifier. Use this constructor to reconstruct instances of existing command messages, which have already been assigned an identifier.

Parameters:
identifier - the unique identifier of this message
commandName - The name of the command
payload - the payload for the Message
newMetaData - The meta data for this message (null results in empty meta data)

GenericCommandMessage

protected GenericCommandMessage(GenericCommandMessage<T> original,
                                Map<String,?> metaData)
Copy constructor that allows creation of a new GenericCommandMessage with modified metaData. All information from the original is copied, except for the metaData.

Parameters:
original - The original message
metaData - The MetaData for the new message
Method Detail

asCommandMessage

public static CommandMessage asCommandMessage(Object command)
Returns the given command as a CommandMessage. If command already implements CommandMessage, it is returned as-is. Otherwise, the given command is wrapped into a GenericCommandMessage as its payload.

Parameters:
command - the command to wrap as CommandMessage
Returns:
a CommandMessage containing given command as payload, or command if it already implements CommandMessage.

getCommandName

public String getCommandName()
Description copied from interface: CommandMessage
Returns the name of the command to execute. This is an indication of what should be done, using the payload as parameter.

Specified by:
getCommandName in interface CommandMessage<T>
Returns:
the name of the command

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.

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

withMetaData

public GenericCommandMessage<T> withMetaData(Map<String,?> newMetaData)
Description copied from interface: CommandMessage
Returns a copy of this CommandMessage 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 CommandMessage<T>
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 GenericCommandMessage<T> andMetaData(Map<String,?> additionalMetaData)
Description copied from interface: CommandMessage
Returns a copy of this CommandMessage with it MetaData merged with the given metaData. The payload remains unchanged.

Specified by:
andMetaData in interface CommandMessage<T>
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.