@ThreadSafe public final class RPCProtoMessage extends RPCMessage
Encoded format: [proto message length][serialized proto message][data buffer] The proto message length doesn't include the length of itself (the length field).
Note: The data buffer must be released when it is not used. Usually this is how it is released:
1. On the consumer side, a RPCProtoMessage
is decoded and the data buffer is extracted.
The ownership of the data buffer is transferred from then on.
2. On the producer side, a RPCProtoMessage
is created. It will be sent on the wire via
netty which will take ownership of the data buffer.
Given the above usage patterns, RPCProtoMessage
doesn't provide a 'release' interface
to avoid confusing the user.
RPCMessage.Type
Constructor and Description |
---|
RPCProtoMessage(byte[] serialized,
ProtoMessage prototype,
DataBuffer data)
Creates an instance of
RPCProtoMessage from a serialized proto message. |
RPCProtoMessage(ProtoMessage message)
Creates an instance of
RPCProtoMessage without data part. |
RPCProtoMessage(ProtoMessage message,
DataBuffer data)
Creates an instance of
RPCProtoMessage . |
Modifier and Type | Method and Description |
---|---|
static RPCProtoMessage |
createCancelResponse()
Creates a response in CANCELLED state.
|
static RPCProtoMessage |
createOkResponse(DataBuffer data)
Creates an OK response with data.
|
static RPCProtoMessage |
createResponse(AlluxioStatusException se)
Creates a response for a given
AlluxioStatusException . |
static RPCProtoMessage |
createResponse(io.grpc.Status status,
String message,
DataBuffer data)
Creates a response for a given status, message, and data buffer.
|
static RPCProtoMessage |
decode(io.netty.buffer.ByteBuf in,
ProtoMessage prototype)
Decodes the message from a buffer.
|
void |
encode(io.netty.buffer.ByteBuf out)
Encodes the message to the output
ByteBuf . |
static io.grpc.Status |
fromProto(Status.PStatus status)
Creates a
Status from a protocol buffer type status. |
int |
getEncodedLength()
Returns the number bytes for the message when it is encoded.
|
ProtoMessage |
getMessage() |
DataBuffer |
getPayloadDataBuffer()
Returns the data buffer of the payload.
|
RPCMessage.Type |
getType()
Returns the type of the message.
|
boolean |
hasPayload()
Returns true if the message has a payload.
|
static Status.PStatus |
toProto(io.grpc.Status status)
Converts an internal exception status to a protocol buffer type status.
|
String |
toString() |
void |
validate()
Validates the message.
|
createFrameDecoder, decodeMessage
public RPCProtoMessage(ProtoMessage message, DataBuffer data)
RPCProtoMessage
.message
- the messagedata
- the data which can be null. Ownership is taken by this classpublic RPCProtoMessage(ProtoMessage message)
RPCProtoMessage
without data part.message
- the messagepublic RPCProtoMessage(byte[] serialized, ProtoMessage prototype, DataBuffer data)
RPCProtoMessage
from a serialized proto message.serialized
- the serialized messageprototype
- the prototype of the message used to identify the type of the messagedata
- the data which can be nullpublic int getEncodedLength()
EncodedMessage
public void encode(io.netty.buffer.ByteBuf out)
EncodedMessage
ByteBuf
.out
- the output ByteBuf where the message should be encodedpublic static RPCProtoMessage decode(io.netty.buffer.ByteBuf in, ProtoMessage prototype)
in
- the bufferprototype
- a message prototype used to infer the type of the messagepublic RPCMessage.Type getType()
RPCMessage
getType
in class RPCMessage
public void validate()
RPCMessage
validate
in class RPCMessage
public boolean hasPayload()
RPCMessage
hasPayload
in class RPCMessage
public DataBuffer getPayloadDataBuffer()
RPCMessage
getPayloadDataBuffer
in class RPCMessage
public ProtoMessage getMessage()
public static RPCProtoMessage createResponse(AlluxioStatusException se)
AlluxioStatusException
.se
- the AlluxioStatusException
RPCProtoMessage
public static RPCProtoMessage createResponse(io.grpc.Status status, String message, DataBuffer data)
status
- the status codemessage
- the messagedata
- the data bufferRPCProtoMessage
public static RPCProtoMessage createOkResponse(DataBuffer data)
data
- the datapublic static RPCProtoMessage createCancelResponse()
public static Status.PStatus toProto(io.grpc.Status status)
status
- the status to convertpublic static io.grpc.Status fromProto(Status.PStatus status)
Status
from a protocol buffer type status.status
- the protocol buffer type statusStatus
Copyright © 2023. All Rights Reserved.