Interface ResultMessage<R>

Type Parameters:
R - The type of payload contained in this Message
All Superinterfaces:
Message<R>, Serializable
All Known Subinterfaces:
CommandResultMessage<R>, QueryResponseMessage<T>, SubscriptionQueryUpdateMessage<U>
All Known Implementing Classes:
ConvertingResponseMessage, GenericCommandResultMessage, GenericQueryResponseMessage, GenericResultMessage, GenericSubscriptionQueryUpdateMessage, GrpcBackedResponseMessage

public interface ResultMessage<R> extends Message<R>
Message that represents a result of handling some form of request message.
Since:
4.0
Author:
Milan Savic
  • Method Details

    • isExceptional

      boolean isExceptional()
      Indicates whether the ResultMessage represents unsuccessful execution.
      Returns:
      true if execution was unsuccessful, false otherwise
    • optionalExceptionResult

      Optional<Throwable> optionalExceptionResult()
      Returns the Exception in case of exceptional result message or an empty Optional in case of successful execution.
      Returns:
      an Optional containing exception result or an empty Optional in case of a successful execution
    • exceptionResult

      default Throwable exceptionResult() throws IllegalStateException
      Returns the exception result. This method is to be called if isExceptional() returns true.
      Returns:
      a Throwable defining the exception result
      Throws:
      IllegalStateException - if this ResultMessage is not exceptional
    • exceptionDetails

      default <D> Optional<D> exceptionDetails()
      If the this message contains an exception result, returns the details provided in the exception, if available. If this message does not carry an exception result, or the exception result doesn't provide any application-specific details, an empty optional is returned.
      Type Parameters:
      D - The type of application-specific details expected
      Returns:
      an optional containing application-specific error details, if present
    • serializePayload

      default <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>
      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
    • serializeExceptionResult

      default <T> SerializedObject<T> serializeExceptionResult(Serializer serializer, Class<T> expectedRepresentation)
      Serializes the exception result. Will create a RemoteExceptionDescription from the Optional exception in this ResultMessage instead of serializing the original exception.
      Type Parameters:
      T - the generic type representing the expected format
      Parameters:
      serializer - the Serializer used to serialize the exception
      expectedRepresentation - a Class representing the expected format
      Returns:
      the serialized exception as a SerializedObject
    • withMetaData

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

      ResultMessage<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>
      Parameters:
      metaData - The MetaData to merge with
      Returns:
      a copy of this message with the given MetaData