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 Details

    • GenericQueryResponseMessage

      public GenericQueryResponseMessage(R result)
      Initialize the response message with given result.
      Parameters:
      result - The result reported by the Query Handler, may not be null
    • GenericQueryResponseMessage

      public GenericQueryResponseMessage(Class<R> declaredResultType, R result)
      Initialize a response message with given result and declaredResultType. This constructor allows the actual result to be null.
      Parameters:
      declaredResultType - The declared type of the result
      result - The actual result. May be null
    • GenericQueryResponseMessage

      public GenericQueryResponseMessage(Class<R> declaredResultType, Throwable exception)
      Initialize the response message with given declaredResultType and exception.
      Parameters:
      declaredResultType - The declared type of the Query Response Message to be created
      exception - The Exception describing the cause of an error
    • GenericQueryResponseMessage

      public GenericQueryResponseMessage(R result, Map<String,?> metaData)
      Initialize the response message with given result and metaData.
      Parameters:
      result - The result reported by the Query Handler, may not be null
      metaData - The meta data to contain in the message
    • GenericQueryResponseMessage

      public GenericQueryResponseMessage(Class<R> declaredResultType, R result, Map<String,?> metaData)
      Initialize the response message with a specific declaredResultType, the given result as payload and metaData.
      Parameters:
      declaredResultType - A Class denoting the declared result type of this query response message
      result - The result reported by the Query Handler, may be null
      metaData - The meta data to contain in the message
    • GenericQueryResponseMessage

      public GenericQueryResponseMessage(Class<R> declaredResultType, Throwable exception, Map<String,?> metaData)
      Initialize the response message with given declaredResultType, exception and metaData.
      Parameters:
      declaredResultType - The declared type of the Query Response Message to be created
      exception - The Exception describing the cause of an error
      metaData - The meta data to contain in the message
    • GenericQueryResponseMessage

      public GenericQueryResponseMessage(Message<R> delegate)
      Copy-constructor that takes the payload, meta data and message identifier of the given delegate for 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

      public GenericQueryResponseMessage(Message<R> delegate, Throwable exception)
      Copy-constructor that takes the payload, meta data and message identifier of the given delegate for this message and given exception as 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 from
      exception - The Exception describing the cause of an error
  • Method Details

    • asResponseMessage

      public static <R> QueryResponseMessage<R> asResponseMessage(Object result)
      Creates a QueryResponseMessage for the given result. 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 given result with a declaredType as 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 a NullPointerException. 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 given declaredType and exception.
      Type Parameters:
      R - The type of the payload
      Parameters:
      declaredType - The declared type of the Query Response Message to be created
      exception - The Exception describing the cause of an error
      Returns:
      a message containing exception result
    • withMetaData

      public GenericQueryResponseMessage<R> withMetaData(@Nonnull Map<String,?> metaData)
      Description copied from interface: Message
      Returns a copy of this Message 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 Message<R>
      Specified by:
      withMetaData in interface QueryResponseMessage<R>
      Specified by:
      withMetaData in interface ResultMessage<R>
      Overrides:
      withMetaData in class GenericResultMessage<R>
      Parameters:
      metaData - The new MetaData for the Message
      Returns:
      a copy of this message with the given MetaData
    • andMetaData

      public GenericQueryResponseMessage<R> andMetaData(@Nonnull Map<String,?> additionalMetaData)
      Description copied from interface: Message
      Returns a copy of this Message with it MetaData merged with the given metaData. The payload remains unchanged.
      Specified by:
      andMetaData in interface Message<R>
      Specified by:
      andMetaData in interface QueryResponseMessage<R>
      Specified by:
      andMetaData in interface ResultMessage<R>
      Overrides:
      andMetaData in class GenericResultMessage<R>
      Parameters:
      additionalMetaData - The MetaData to merge with
      Returns:
      a copy of this message with the given MetaData