Class MessageSerializer<REQ extends MessageBody,RESP extends MessageBody>
- java.lang.Object
-
- org.apache.flink.queryablestate.network.messages.MessageSerializer<REQ,RESP>
-
- Type Parameters:
REQ- Type of the requests of the protocol.RESP- Type of the responses of the protocol.
@Internal public final class MessageSerializer<REQ extends MessageBody,RESP extends MessageBody> extends Object
Serialization and deserialization of messages exchanged betweenclientandserver.The binary messages have the following format:
<------ Frame -------------------------> +----------------------------------------+ | HEADER (8) | PAYLOAD (VAR) | +------------------+----------------------------------------+ | FRAME LENGTH (4) | VERSION (4) | TYPE (4) | CONTENT (VAR) | +------------------+----------------------------------------+The concrete content of a message depends on the
MessageType.
-
-
Constructor Summary
Constructors Constructor Description MessageSerializer(MessageDeserializer<REQ> requestDeser, MessageDeserializer<RESP> responseDeser)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MessageTypedeserializeHeader(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf buf)De-serializes the header and returns theMessageType.REQdeserializeRequest(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf buf)De-serializes the request sent to theAbstractServerBase.static RequestFailuredeserializeRequestFailure(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf buf)De-serializes theRequestFailuresent to theClientin case of protocol related errors.RESPdeserializeResponse(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf buf)De-serializes the response sent to theClient.static ThrowabledeserializeServerFailure(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf buf)De-serializes the failure message sent to theClientin case of server related errors.static longgetRequestId(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf buf)De-serializes the header and returns theMessageType.static <REQ extends MessageBody>
org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufserializeRequest(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufAllocator alloc, long requestId, REQ request)Serializes the request sent to theAbstractServerBase.static org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufserializeRequestFailure(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufAllocator alloc, long requestId, Throwable cause)Serializes the exception containing the failure message sent to theClientin case of protocol related errors.static <RESP extends MessageBody>
org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufserializeResponse(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufAllocator alloc, long requestId, RESP response)Serializes the response sent to theClient.static org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufserializeServerFailure(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufAllocator alloc, Throwable cause)Serializes the failure message sent to theClientin case of server related errors.
-
-
-
Constructor Detail
-
MessageSerializer
public MessageSerializer(MessageDeserializer<REQ> requestDeser, MessageDeserializer<RESP> responseDeser)
-
-
Method Detail
-
serializeRequest
public static <REQ extends MessageBody> org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf serializeRequest(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufAllocator alloc, long requestId, REQ request)
Serializes the request sent to theAbstractServerBase.- Parameters:
alloc- TheByteBufAllocatorused to allocate the buffer to serialize the message into.requestId- The id of the request to which the message refers to.request- The request to be serialized.- Returns:
- A
ByteBufcontaining the serialized message.
-
serializeResponse
public static <RESP extends MessageBody> org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf serializeResponse(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufAllocator alloc, long requestId, RESP response)
Serializes the response sent to theClient.- Parameters:
alloc- TheByteBufAllocatorused to allocate the buffer to serialize the message into.requestId- The id of the request to which the message refers to.response- The response to be serialized.- Returns:
- A
ByteBufcontaining the serialized message.
-
serializeRequestFailure
public static org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf serializeRequestFailure(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufAllocator alloc, long requestId, Throwable cause) throws IOExceptionSerializes the exception containing the failure message sent to theClientin case of protocol related errors.- Parameters:
alloc- TheByteBufAllocatorused to allocate the buffer to serialize the message into.requestId- The id of the request to which the message refers to.cause- The exception thrown at the server.- Returns:
- A
ByteBufcontaining the serialized message. - Throws:
IOException
-
serializeServerFailure
public static org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf serializeServerFailure(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufAllocator alloc, Throwable cause) throws IOExceptionSerializes the failure message sent to theClientin case of server related errors.- Parameters:
alloc- TheByteBufAllocatorused to allocate the buffer to serialize the message into.cause- The exception thrown at the server.- Returns:
- The failure message.
- Throws:
IOException
-
deserializeHeader
public static MessageType deserializeHeader(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf buf)
De-serializes the header and returns theMessageType.The buffer is expected to be at the header position.
- Parameters:
buf- TheByteBufcontaining the serialized header.- Returns:
- The message type.
- Throws:
IllegalStateException- If unexpected message version or message type.
-
getRequestId
public static long getRequestId(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf buf)
De-serializes the header and returns theMessageType.The buffer is expected to be at the request id position.
- Parameters:
buf- TheByteBufcontaining the serialized request id.- Returns:
- The request id.
-
deserializeRequest
public REQ deserializeRequest(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf buf)
De-serializes the request sent to theAbstractServerBase.The buffer is expected to be at the request position.
- Parameters:
buf- TheByteBufcontaining the serialized request.- Returns:
- The request.
-
deserializeResponse
public RESP deserializeResponse(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf buf)
De-serializes the response sent to theClient.The buffer is expected to be at the response position.
- Parameters:
buf- TheByteBufcontaining the serialized response.- Returns:
- The response.
-
deserializeRequestFailure
public static RequestFailure deserializeRequestFailure(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf buf) throws IOException, ClassNotFoundException
De-serializes theRequestFailuresent to theClientin case of protocol related errors.The buffer is expected to be at the correct position.
- Parameters:
buf- TheByteBufcontaining the serialized failure message.- Returns:
- The failure message.
- Throws:
IOExceptionClassNotFoundException
-
deserializeServerFailure
public static Throwable deserializeServerFailure(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf buf) throws IOException, ClassNotFoundException
De-serializes the failure message sent to theClientin case of server related errors.The buffer is expected to be at the correct position.
- Parameters:
buf- TheByteBufcontaining the serialized failure message.- Returns:
- The failure message.
- Throws:
IOExceptionClassNotFoundException
-
-