T
- The type of payload contained in this Messagepublic class GenericCommandMessage<T> extends MessageDecorator<T> implements CommandMessage<T>
Constructor and Description |
---|
GenericCommandMessage(Message<T> delegate,
String commandName)
Create a CommandMessage from the given
delegate message containing payload, metadata and message
identifier, and the given commandName . |
GenericCommandMessage(T payload)
Create a CommandMessage with the given
command as payload and empty metaData |
GenericCommandMessage(T payload,
Map<String,?> metaData)
Create a CommandMessage with the given
command as payload. |
Modifier and Type | Method and Description |
---|---|
GenericCommandMessage<T> |
andMetaData(Map<String,?> metaData)
Returns a copy of this CommandMessage with it MetaData merged with the given
metaData . |
static <C> CommandMessage<C> |
asCommandMessage(Object command)
Returns the given command as a
CommandMessage . |
protected void |
describeTo(StringBuilder stringBuilder)
Describe the message specific properties to the given
stringBuilder . |
protected String |
describeType()
Describe the type of message, used in
MessageDecorator.toString() . |
String |
getCommandName()
Returns the name of the command to execute.
|
GenericCommandMessage<T> |
withMetaData(Map<String,?> metaData)
Returns a copy of this CommandMessage with the given
metaData . |
getDelegate, getIdentifier, getMetaData, getPayload, getPayloadType, serializeMetaData, serializePayload, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getIdentifier, getMetaData, getPayload, getPayloadType, serializeMetaData, serializePayload
public GenericCommandMessage(@Nonnull T payload)
command
as payload and empty metaDatapayload
- the payload for the Messagepublic GenericCommandMessage(@Nonnull T payload, @Nonnull Map<String,?> metaData)
command
as payload.payload
- the payload for the MessagemetaData
- The meta data for this messagepublic GenericCommandMessage(@Nonnull Message<T> delegate, @Nonnull String commandName)
delegate
message containing payload, metadata and message
identifier, and the given commandName
.delegate
- the delegate messagecommandName
- The name of the commandpublic static <C> CommandMessage<C> asCommandMessage(@Nonnull Object command)
CommandMessage
. If command
already implements CommandMessage
, it is returned as-is. When the command
is another implementation of Message
, the
Message.getPayload()
and Message.getMetaData()
are used as input for a new GenericCommandMessage
. Otherwise, the given command
is wrapped into a GenericCommandMessage
as
its payload.command
- The command to wrap as CommandMessage
.CommandMessage
containing given command
as payload, a command
if it already
implements CommandMessage
, or a CommandMessage
based on the result of Message.getPayload()
and Message.getMetaData()
for other Message
implementations.public String getCommandName()
CommandMessage
getCommandName
in interface CommandMessage<T>
public GenericCommandMessage<T> withMetaData(@Nonnull Map<String,?> metaData)
CommandMessage
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.withMetaData
in interface CommandMessage<T>
withMetaData
in interface Message<T>
metaData
- The new MetaData for the Messagepublic GenericCommandMessage<T> andMetaData(@Nonnull Map<String,?> metaData)
CommandMessage
metaData
. The payload
remains unchanged.andMetaData
in interface CommandMessage<T>
andMetaData
in interface Message<T>
metaData
- The MetaData to merge withprotected void describeTo(StringBuilder stringBuilder)
MessageDecorator
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.
describeTo
in class MessageDecorator<T>
stringBuilder
- the builder to append data toprotected String describeType()
MessageDecorator
MessageDecorator.toString()
.
Defaults to the simple class name of the actual instance.
describeType
in class MessageDecorator<T>
Copyright © 2010–2024. All rights reserved.