Package org.axonframework.messaging
Class GenericResultMessage<R>
java.lang.Object
org.axonframework.messaging.MessageDecorator<R>
org.axonframework.messaging.GenericResultMessage<R>
- All Implemented Interfaces:
Serializable,Message<R>,ResultMessage<R>
- Direct Known Subclasses:
GenericCommandResultMessage,GenericQueryResponseMessage,GenericSubscriptionQueryUpdateMessage
Generic implementation of
ResultMessage.- Since:
- 4.0
- Author:
- Milan Savic
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionGenericResultMessage(Throwable exception) Creates a ResultMessage with the givenexception.GenericResultMessage(Throwable exception, Map<String, ?> metaData) Creates a ResultMessage with the givenexceptionandmetaData.GenericResultMessage(Message<R> delegate) Creates a new ResultMessage with givendelegatemessage.GenericResultMessage(Message<R> delegate, Throwable exception) Creates a ResultMessage with givendelegatemessage andexception.GenericResultMessage(R result) Creates a ResultMessage with the givenresultas the payload.GenericResultMessage(R result, Map<String, ?> metaData) Creates a ResultMessage with the givenresultas the payload andmetaDataas the meta data. -
Method Summary
Modifier and TypeMethodDescriptionandMetaData(Map<String, ?> metaData) Returns a copy of this Message with it MetaData merged with the givenmetaData.static <T> ResultMessage<T> asResultMessage(Object result) Returns the givenresultas aResultMessageinstance.static <T> ResultMessage<T> asResultMessage(Throwable exception) Creates a ResultMessage with the givenexceptionresult.protected voiddescribeTo(StringBuilder stringBuilder) Describe the message specific properties to the givenstringBuilder.protected StringDescribe the type of message, used inMessageDecorator.toString().Returns the payload of this message.booleanIndicates whether the ResultMessage represents unsuccessful execution.Returns the Exception in case of exceptional result message or an emptyOptionalin case of successful execution.<S> SerializedObject<S> serializePayload(Serializer serializer, Class<S> expectedRepresentation) Serialize the payload of this message to theexpectedRepresentationusing givenserializer.withMetaData(Map<String, ?> metaData) Returns a copy of this Message with the givenmetaData.Methods inherited from class org.axonframework.messaging.MessageDecorator
getDelegate, getIdentifier, getMetaData, getPayloadType, serializeMetaData, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.axonframework.messaging.Message
getIdentifier, getMetaData, getPayloadType, serializeMetaDataMethods inherited from interface org.axonframework.messaging.ResultMessage
exceptionDetails, exceptionResult, serializeExceptionResult
-
Constructor Details
-
GenericResultMessage
Creates a ResultMessage with the givenresultas the payload.- Parameters:
result- the payload for the Message
-
GenericResultMessage
Creates a ResultMessage with the givenexception.- Parameters:
exception- the Exception describing the cause of an error
-
GenericResultMessage
Creates a ResultMessage with the givenresultas the payload andmetaDataas the meta data.- Parameters:
result- the payload for the MessagemetaData- the meta data for the Message
-
GenericResultMessage
Creates a ResultMessage with the givenexceptionandmetaData.- Parameters:
exception- the Exception describing the cause of an errormetaData- the meta data for the Message
-
GenericResultMessage
Creates a new ResultMessage with givendelegatemessage.- Parameters:
delegate- the message delegate
-
GenericResultMessage
Creates a ResultMessage with givendelegatemessage andexception.- Parameters:
delegate- the Message delegateexception- the Exception describing the cause of an error
-
-
Method Details
-
asResultMessage
Returns the givenresultas aResultMessageinstance. Ifresultalready implementsResultMessage, it is returned as-is. IfresultimplementsMessage, payload and meta data will be used to construct newGenericResultMessage. Otherwise, the givenresultis wrapped into aGenericResultMessageas its payload.- Type Parameters:
T- The type of the payload contained in returned Message- Parameters:
result- the command result to be wrapped asResultMessage- Returns:
- a Message containing given
resultas payload, orresultif already implementsResultMessage
-
asResultMessage
Creates a ResultMessage with the givenexceptionresult.- Type Parameters:
T- the type of payload- Parameters:
exception- the Exception describing the cause of an error- Returns:
- a message containing exception result
-
isExceptional
public boolean isExceptional()Description copied from interface:ResultMessageIndicates whether the ResultMessage represents unsuccessful execution.- Specified by:
isExceptionalin interfaceResultMessage<R>- Returns:
trueif execution was unsuccessful,falseotherwise
-
optionalExceptionResult
Description copied from interface:ResultMessageReturns the Exception in case of exceptional result message or an emptyOptionalin case of successful execution.- Specified by:
optionalExceptionResultin interfaceResultMessage<R>- Returns:
- an
Optionalcontaining exception result or an empty Optional in case of a successful execution
-
serializePayload
public <S> SerializedObject<S> serializePayload(Serializer serializer, Class<S> expectedRepresentation) Description copied from interface:MessageSerialize the payload of this message to theexpectedRepresentationusing givenserializer. This method should return the same SerializedObject instance when invoked multiple times using the same serializer.- Specified by:
serializePayloadin interfaceMessage<R>- Specified by:
serializePayloadin interfaceResultMessage<R>- Overrides:
serializePayloadin classMessageDecorator<R>- Type Parameters:
S- The type of the serialized data- Parameters:
serializer- The serializer to serialize payload withexpectedRepresentation- The type of data to serialize to- Returns:
- a SerializedObject containing the serialized representation of the message's payload
-
withMetaData
Description copied from interface:MessageReturns a copy of this Message with the givenmetaData. The payload remains unchanged. While the implementation returned may be different than the implementation ofthis, implementations must take special care in returning the same type of Message (e.g. EventMessage, DomainEventMessage) to prevent errors further downstream.- Specified by:
withMetaDatain interfaceMessage<R>- Specified by:
withMetaDatain interfaceResultMessage<R>- Parameters:
metaData- The new MetaData for the Message- Returns:
- a copy of this message with the given MetaData
-
andMetaData
Description copied from interface:MessageReturns a copy of this Message with it MetaData merged with the givenmetaData. The payload remains unchanged.- Specified by:
andMetaDatain interfaceMessage<R>- Specified by:
andMetaDatain interfaceResultMessage<R>- Parameters:
metaData- The MetaData to merge with- Returns:
- a copy of this message with the given MetaData
-
describeTo
Description copied from class:MessageDecoratorDescribe the message specific properties to the givenstringBuilder. 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.
- Overrides:
describeToin classMessageDecorator<R>- Parameters:
stringBuilder- the builder to append data to
-
describeType
Description copied from class:MessageDecoratorDescribe the type of message, used inMessageDecorator.toString().Defaults to the simple class name of the actual instance.
- Overrides:
describeTypein classMessageDecorator<R>- Returns:
- the type of message
-
getPayload
Description copied from interface:MessageReturns the payload of this message. The payload is the application-specific information.- Specified by:
getPayloadin interfaceMessage<R>- Overrides:
getPayloadin classMessageDecorator<R>- Returns:
- the payload of this message
-