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

public class GenericResultMessage<R> extends MessageDecorator<R> implements ResultMessage<R>
Generic implementation of ResultMessage.
Since:
4.0
Author:
Milan Savic
See Also:
  • Constructor Details

    • GenericResultMessage

      public GenericResultMessage(R result)
      Creates a ResultMessage with the given result as the payload.
      Parameters:
      result - the payload for the Message
    • GenericResultMessage

      public GenericResultMessage(Throwable exception)
      Creates a ResultMessage with the given exception.
      Parameters:
      exception - the Exception describing the cause of an error
    • GenericResultMessage

      public GenericResultMessage(R result, Map<String,?> metaData)
      Creates a ResultMessage with the given result as the payload and metaData as the meta data.
      Parameters:
      result - the payload for the Message
      metaData - the meta data for the Message
    • GenericResultMessage

      public GenericResultMessage(Throwable exception, Map<String,?> metaData)
      Creates a ResultMessage with the given exception and metaData.
      Parameters:
      exception - the Exception describing the cause of an error
      metaData - the meta data for the Message
    • GenericResultMessage

      public GenericResultMessage(Message<R> delegate)
      Creates a new ResultMessage with given delegate message.
      Parameters:
      delegate - the message delegate
    • GenericResultMessage

      public GenericResultMessage(Message<R> delegate, Throwable exception)
      Creates a ResultMessage with given delegate message and exception.
      Parameters:
      delegate - the Message delegate
      exception - the Exception describing the cause of an error
  • Method Details

    • asResultMessage

      public static <T> ResultMessage<T> asResultMessage(Object result)
      Returns the given 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.
      Type Parameters:
      T - The type of the payload contained in returned Message
      Parameters:
      result - the command result to be wrapped as ResultMessage
      Returns:
      a Message containing given result as payload, or result if already implements ResultMessage
    • asResultMessage

      public static <T> ResultMessage<T> asResultMessage(Throwable exception)
      Creates a ResultMessage with the given exception result.
      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: ResultMessage
      Indicates whether the ResultMessage represents unsuccessful execution.
      Specified by:
      isExceptional in interface ResultMessage<R>
      Returns:
      true if execution was unsuccessful, false otherwise
    • optionalExceptionResult

      public Optional<Throwable> optionalExceptionResult()
      Description copied from interface: ResultMessage
      Returns the Exception in case of exceptional result message or an empty Optional in case of successful execution.
      Specified by:
      optionalExceptionResult in interface ResultMessage<R>
      Returns:
      an Optional containing 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: Message
      Serialize the payload of this message to the expectedRepresentation using given serializer. This method should return the same SerializedObject instance when invoked multiple times using the same serializer.
      Specified by:
      serializePayload in interface Message<R>
      Specified by:
      serializePayload in interface ResultMessage<R>
      Overrides:
      serializePayload in class MessageDecorator<R>
      Type Parameters:
      S - The type of the serialized data
      Parameters:
      serializer - The serializer to serialize payload with
      expectedRepresentation - The type of data to serialize to
      Returns:
      a SerializedObject containing the serialized representation of the message's payload
    • withMetaData

      public GenericResultMessage<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 ResultMessage<R>
      Parameters:
      metaData - The new MetaData for the Message
      Returns:
      a copy of this message with the given MetaData
    • andMetaData

      public GenericResultMessage<R> andMetaData(@Nonnull Map<String,?> metaData)
      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 ResultMessage<R>
      Parameters:
      metaData - The MetaData to merge with
      Returns:
      a copy of this message with the given MetaData
    • describeTo

      protected void describeTo(StringBuilder stringBuilder)
      Description copied from class: MessageDecorator
      Describe the message specific properties to the given 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.

      Overrides:
      describeTo in class MessageDecorator<R>
      Parameters:
      stringBuilder - the builder to append data to
    • describeType

      protected String describeType()
      Description copied from class: MessageDecorator
      Describe the type of message, used in MessageDecorator.toString().

      Defaults to the simple class name of the actual instance.

      Overrides:
      describeType in class MessageDecorator<R>
      Returns:
      the type of message
    • getPayload

      public R getPayload()
      Description copied from interface: Message
      Returns the payload of this message. The payload is the application-specific information.
      Specified by:
      getPayload in interface Message<R>
      Overrides:
      getPayload in class MessageDecorator<R>
      Returns:
      the payload of this message