Package org.axonframework.queryhandling
Class GenericQueryResponseMessage<R>
java.lang.Object
org.axonframework.messaging.MessageDecorator<R>
org.axonframework.messaging.GenericResultMessage<R>
org.axonframework.queryhandling.GenericQueryResponseMessage<R>
- Type Parameters:
R- The type of return value contained in this response
- All Implemented Interfaces:
Serializable,Message<R>,ResultMessage<R>,QueryResponseMessage<R>
public class GenericQueryResponseMessage<R>
extends GenericResultMessage<R>
implements QueryResponseMessage<R>
QueryResponseMessage implementation that takes all properties as constructor parameters.
- Since:
- 3.2
- Author:
- Allard Buijze
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionGenericQueryResponseMessage(Class<R> declaredResultType, Throwable exception) Initialize the response message with givendeclaredResultTypeandexception.GenericQueryResponseMessage(Class<R> declaredResultType, Throwable exception, Map<String, ?> metaData) Initialize the response message with givendeclaredResultType,exceptionandmetaData.GenericQueryResponseMessage(Class<R> declaredResultType, R result) Initialize a response message with givenresultanddeclaredResultType.Initialize the response message with a specificdeclaredResultType, the givenresultas payload andmetaData.GenericQueryResponseMessage(Message<R> delegate) Copy-constructor that takes the payload, meta data and message identifier of the givendelegatefor this message.GenericQueryResponseMessage(Message<R> delegate, Throwable exception) Copy-constructor that takes the payload, meta data and message identifier of the givendelegatefor this message and givenexceptionas a cause for the failure.GenericQueryResponseMessage(R result) Initialize the response message with givenresult.GenericQueryResponseMessage(R result, Map<String, ?> metaData) Initialize the response message with givenresultandmetaData. -
Method Summary
Modifier and TypeMethodDescriptionandMetaData(Map<String, ?> additionalMetaData) Returns a copy of this Message with it MetaData merged with the givenmetaData.static <R> QueryResponseMessage<R> asNullableResponseMessage(Class<R> declaredType, Object result) Creates a QueryResponseMessage for the givenresultwith adeclaredTypeas the result type.static <R> QueryResponseMessage<R> asResponseMessage(Class<R> declaredType, Throwable exception) Creates a Query Response Message with givendeclaredTypeandexception.static <R> QueryResponseMessage<R> asResponseMessage(Object result) Creates a QueryResponseMessage for the givenresult.withMetaData(Map<String, ?> metaData) Returns a copy of this Message with the givenmetaData.Methods inherited from class org.axonframework.messaging.GenericResultMessage
asResultMessage, asResultMessage, describeTo, describeType, getPayload, isExceptional, optionalExceptionResult, serializePayloadMethods 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, getPayload, getPayloadType, serializeMetaDataMethods inherited from interface org.axonframework.messaging.ResultMessage
exceptionDetails, exceptionResult, isExceptional, optionalExceptionResult, serializeExceptionResult, serializePayload
-
Constructor Details
-
GenericQueryResponseMessage
Initialize the response message with givenresult.- Parameters:
result- The result reported by the Query Handler, may not benull
-
GenericQueryResponseMessage
Initialize a response message with givenresultanddeclaredResultType. This constructor allows the actual result to benull.- Parameters:
declaredResultType- The declared type of the resultresult- The actual result. May benull
-
GenericQueryResponseMessage
Initialize the response message with givendeclaredResultTypeandexception.- Parameters:
declaredResultType- The declared type of the Query Response Message to be createdexception- The Exception describing the cause of an error
-
GenericQueryResponseMessage
Initialize the response message with givenresultandmetaData.- Parameters:
result- The result reported by the Query Handler, may not benullmetaData- The meta data to contain in the message
-
GenericQueryResponseMessage
Initialize the response message with a specificdeclaredResultType, the givenresultas payload andmetaData.- Parameters:
declaredResultType- AClassdenoting the declared result type of this query response messageresult- The result reported by the Query Handler, may benullmetaData- The meta data to contain in the message
-
GenericQueryResponseMessage
public GenericQueryResponseMessage(Class<R> declaredResultType, Throwable exception, Map<String, ?> metaData) Initialize the response message with givendeclaredResultType,exceptionandmetaData.- Parameters:
declaredResultType- The declared type of the Query Response Message to be createdexception- The Exception describing the cause of an errormetaData- The meta data to contain in the message
-
GenericQueryResponseMessage
Copy-constructor that takes the payload, meta data and message identifier of the givendelegatefor this message.Unlike the other constructors, this constructor will not attempt to retrieve any correlation data from the Unit of Work.
- Parameters:
delegate- The message to retrieve message details from
-
GenericQueryResponseMessage
Copy-constructor that takes the payload, meta data and message identifier of the givendelegatefor this message and givenexceptionas a cause for the failure.Unlike the other constructors, this constructor will not attempt to retrieve any correlation data from the Unit of Work.
- Parameters:
delegate- The message to retrieve message details fromexception- The Exception describing the cause of an error
-
-
Method Details
-
asResponseMessage
Creates a QueryResponseMessage for the givenresult. If result already implements QueryResponseMessage, it is returned directly. Otherwise a new QueryResponseMessage is created with the result as payload.- Type Parameters:
R- The type of response expected- Parameters:
result- The result of a Query, to be wrapped in a QueryResponseMessage- Returns:
- a QueryResponseMessage for the given
result, or the result itself, if already a QueryResponseMessage.
-
asNullableResponseMessage
public static <R> QueryResponseMessage<R> asNullableResponseMessage(Class<R> declaredType, Object result) Creates a QueryResponseMessage for the givenresultwith adeclaredTypeas the result type. Providing both the result type and the result allows the creation of a nullable response message, as the implementation does not have to check the type itself, which could result in aNullPointerException. If result already implements QueryResponseMessage, it is returned directly. Otherwise a new QueryResponseMessage is created with the declared type as the result type and the result as payload.- Type Parameters:
R- The type of response expected- Parameters:
declaredType- The declared type of the Query Response Message to be created.result- The result of a Query, to be wrapped in a QueryResponseMessage- Returns:
- a QueryResponseMessage for the given
result, or the result itself, if already a QueryResponseMessage.
-
asResponseMessage
public static <R> QueryResponseMessage<R> asResponseMessage(Class<R> declaredType, Throwable exception) Creates a Query Response Message with givendeclaredTypeandexception.- Type Parameters:
R- The type of the payload- Parameters:
declaredType- The declared type of the Query Response Message to be createdexception- The Exception describing the cause of an error- Returns:
- a message containing exception result
-
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 interfaceQueryResponseMessage<R>- Specified by:
withMetaDatain interfaceResultMessage<R>- Overrides:
withMetaDatain classGenericResultMessage<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 interfaceQueryResponseMessage<R>- Specified by:
andMetaDatain interfaceResultMessage<R>- Overrides:
andMetaDatain classGenericResultMessage<R>- Parameters:
additionalMetaData- The MetaData to merge with- Returns:
- a copy of this message with the given MetaData
-