R
- the type of response expectedpublic class ConvertingResponseMessage<R> extends Object implements QueryResponseMessage<R>
The conversion is generally used to accommodate response types that aren't compatible with serialization, such as
OptionalResponseType
.
Constructor and Description |
---|
ConvertingResponseMessage(ResponseType<R> expectedResponseType,
QueryResponseMessage<?> responseMessage)
Initialize a response message, using
expectedResponseType to convert the payload from the responseMessage , if necessary. |
Modifier and Type | Method and Description |
---|---|
QueryResponseMessage<R> |
andMetaData(Map<String,?> additionalMetaData)
Returns a copy of this QueryResponseMessage with its MetaData merged with given
metaData . |
String |
getIdentifier()
Returns the identifier of this message.
|
MetaData |
getMetaData()
Returns the meta data for this message.
|
R |
getPayload()
Returns the payload of this message.
|
Class<R> |
getPayloadType()
Returns the type of the payload.
|
boolean |
isExceptional()
Indicates whether the ResultMessage represents unsuccessful execution.
|
Optional<Throwable> |
optionalExceptionResult()
Returns the Exception in case of exceptional result message or an empty
Optional in case of successful
execution. |
<T> SerializedObject<T> |
serializeExceptionResult(Serializer serializer,
Class<T> expectedRepresentation)
Serializes the exception result.
|
<R1> SerializedObject<R1> |
serializeMetaData(Serializer serializer,
Class<R1> expectedRepresentation)
Serialize the meta data of this message to the
expectedRepresentation using given serializer . |
<S> SerializedObject<S> |
serializePayload(Serializer serializer,
Class<S> expectedRepresentation)
Serialize the payload of this message to the
expectedRepresentation using given serializer . |
QueryResponseMessage<R> |
withMetaData(Map<String,?> metaData)
Returns a copy of this QueryResponseMessage with the given
metaData . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
exceptionDetails, exceptionResult
public ConvertingResponseMessage(ResponseType<R> expectedResponseType, QueryResponseMessage<?> responseMessage)
expectedResponseType
to convert the payload from the responseMessage
, if necessary.expectedResponseType
- an instance describing the expected response typeresponseMessage
- the message containing the actual response from the handlerpublic <S> SerializedObject<S> serializePayload(Serializer serializer, Class<S> expectedRepresentation)
Message
expectedRepresentation
using given serializer
. This
method should return the same SerializedObject instance when invoked multiple times using the same
serializer.serializePayload
in interface Message<R>
serializePayload
in interface ResultMessage<R>
S
- The type of the serialized dataserializer
- The serializer to serialize payload withexpectedRepresentation
- The type of data to serialize topublic <T> SerializedObject<T> serializeExceptionResult(Serializer serializer, Class<T> expectedRepresentation)
ResultMessage
RemoteExceptionDescription
from the Optional
exception in this ResultMessage instead of serializing the original exception.serializeExceptionResult
in interface ResultMessage<R>
T
- the generic type representing the expected formatserializer
- the Serializer
used to serialize the exceptionexpectedRepresentation
- a Class
representing the expected formatSerializedObject
public <R1> SerializedObject<R1> serializeMetaData(Serializer serializer, Class<R1> expectedRepresentation)
Message
expectedRepresentation
using given serializer
.
This method should return the same SerializedObject instance when invoked multiple times using the same
serializer.serializeMetaData
in interface Message<R>
R1
- The type of the serialized dataserializer
- The serializer to serialize meta data withexpectedRepresentation
- The type of data to serialize topublic boolean isExceptional()
ResultMessage
isExceptional
in interface ResultMessage<R>
true
if execution was unsuccessful, false
otherwisepublic Optional<Throwable> optionalExceptionResult()
ResultMessage
Optional
in case of successful
execution.optionalExceptionResult
in interface ResultMessage<R>
Optional
containing exception result or an empty Optional in case of a successful executionpublic String getIdentifier()
Message
getIdentifier
in interface Message<R>
public MetaData getMetaData()
Message
getMetaData
in interface Message<R>
public R getPayload()
Message
getPayload
in interface Message<R>
public Class<R> getPayloadType()
Message
getPayload().getClass()
, but allows implementations to optimize by using lazy
loading or deserialization.getPayloadType
in interface Message<R>
public QueryResponseMessage<R> withMetaData(@Nonnull Map<String,?> metaData)
QueryResponseMessage
metaData
. The payload remains unchanged.withMetaData
in interface Message<R>
withMetaData
in interface ResultMessage<R>
withMetaData
in interface QueryResponseMessage<R>
metaData
- The new MetaData for the QueryResponseMessagepublic QueryResponseMessage<R> andMetaData(@Nonnull Map<String,?> additionalMetaData)
QueryResponseMessage
metaData
. The payload
remains unchanged.andMetaData
in interface Message<R>
andMetaData
in interface ResultMessage<R>
andMetaData
in interface QueryResponseMessage<R>
additionalMetaData
- The MetaData to merge into the QueryResponseMessageCopyright © 2010–2024. All rights reserved.