public class GenericResultMessage<R> extends MessageDecorator<R> implements ResultMessage<R>
ResultMessage
.Constructor and Description |
---|
GenericResultMessage(Message<R> delegate)
Creates a new ResultMessage with given
delegate message. |
GenericResultMessage(Message<R> delegate,
Throwable exception)
Creates a ResultMessage with given
delegate message and exception . |
GenericResultMessage(R result)
Creates a ResultMessage with the given
result as the payload. |
GenericResultMessage(R result,
Map<String,?> metaData)
Creates a ResultMessage with the given
result as the payload and metaData as the meta data. |
GenericResultMessage(Throwable exception)
Creates a ResultMessage with the given
exception . |
GenericResultMessage(Throwable exception,
Map<String,?> metaData)
Creates a ResultMessage with the given
exception and metaData . |
Modifier and Type | Method and Description |
---|---|
GenericResultMessage<R> |
andMetaData(Map<String,?> metaData)
Returns a copy of this Message with it MetaData merged with the given
metaData . |
static <T> ResultMessage<T> |
asResultMessage(Object result)
Returns the given
result as a ResultMessage instance. |
static <T> ResultMessage<T> |
asResultMessage(Throwable exception)
Creates a ResultMessage with the given
exception result. |
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() . |
R |
getPayload()
Returns the payload of this message.
|
boolean |
isExceptional()
Indicates whether the ResultMessage represents unsuccessful execution.
|
Optional<Throwable> |
optionalExceptionResult()
Returns the Exception in case of exceptional result message or an empty
Optional in case of successful
execution. |
<S> SerializedObject<S> |
serializePayload(Serializer serializer,
Class<S> expectedRepresentation)
Serialize the payload of this message to the
expectedRepresentation using given serializer . |
GenericResultMessage<R> |
withMetaData(Map<String,?> metaData)
Returns a copy of this Message with the given
metaData . |
getDelegate, getIdentifier, getMetaData, getPayloadType, serializeMetaData, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
exceptionDetails, exceptionResult, serializeExceptionResult
getIdentifier, getMetaData, getPayloadType, serializeMetaData
public GenericResultMessage(R result)
result
as the payload.result
- the payload for the Messagepublic GenericResultMessage(Throwable exception)
exception
.exception
- the Exception describing the cause of an errorpublic GenericResultMessage(R result, Map<String,?> metaData)
result
as the payload and metaData
as the meta data.result
- the payload for the MessagemetaData
- the meta data for the Messagepublic GenericResultMessage(Throwable exception, Map<String,?> metaData)
exception
and metaData
.exception
- the Exception describing the cause of an errormetaData
- the meta data for the Messagepublic GenericResultMessage(Message<R> delegate)
delegate
message.delegate
- the message delegatepublic static <T> ResultMessage<T> asResultMessage(Object result)
result
as a ResultMessage
instance. If result
already implements ResultMessage
, it is returned as-is. If result
implements Message
, payload and meta data will be
used to construct new GenericResultMessage
. Otherwise, the given result
is wrapped into a GenericResultMessage
as its payload.T
- The type of the payload contained in returned Messageresult
- the command result to be wrapped as ResultMessage
result
as payload, or result
if already
implements ResultMessage
public static <T> ResultMessage<T> asResultMessage(Throwable exception)
exception
result.T
- the type of payloadexception
- the Exception describing the cause of an errorpublic boolean isExceptional()
ResultMessage
isExceptional
in interface ResultMessage<R>
true
if execution was unsuccessful, false
otherwisepublic Optional<Throwable> optionalExceptionResult()
ResultMessage
Optional
in case of successful
execution.optionalExceptionResult
in interface ResultMessage<R>
Optional
containing exception result or an empty Optional in case of a successful executionpublic <S> SerializedObject<S> serializePayload(Serializer serializer, Class<S> expectedRepresentation)
Message
expectedRepresentation
using given serializer
. This
method should return the same SerializedObject instance when invoked multiple times using the same
serializer.serializePayload
in interface Message<R>
serializePayload
in interface ResultMessage<R>
serializePayload
in class MessageDecorator<R>
S
- The type of the serialized dataserializer
- The serializer to serialize payload withexpectedRepresentation
- The type of data to serialize topublic GenericResultMessage<R> withMetaData(@Nonnull Map<String,?> metaData)
Message
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 Message<R>
withMetaData
in interface ResultMessage<R>
metaData
- The new MetaData for the Messagepublic GenericResultMessage<R> andMetaData(@Nonnull Map<String,?> metaData)
Message
metaData
. The payload remains
unchanged.andMetaData
in interface Message<R>
andMetaData
in interface ResultMessage<R>
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<R>
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<R>
public R getPayload()
Message
getPayload
in interface Message<R>
getPayload
in class MessageDecorator<R>
Copyright © 2010–2023. All rights reserved.