Class ProtobufTranslationImpl
- java.lang.Object
-
- org.apache.calcite.avatica.remote.ProtobufTranslationImpl
-
- All Implemented Interfaces:
ProtobufTranslation
public class ProtobufTranslationImpl extends java.lang.Object implements ProtobufTranslation
Implementation ofProtobufTranslationImplthat translates protobuf requests to POJO requests.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classProtobufTranslationImpl.RequestTranslatorEncapsulate the logic of transforming a protobuf Request message into the Avatica POJO request.(package private) static classProtobufTranslationImpl.ResponseTranslatorEncapsulate the logic of transforming a protobuf Response message into the Avatica POJO Response.
-
Field Summary
Fields Modifier and Type Field Description private static org.slf4j.LoggerLOGprivate static java.util.Map<java.lang.Class<?>,com.google.protobuf.ByteString>MESSAGE_CLASSESprivate static java.util.Map<java.lang.String,ProtobufTranslationImpl.RequestTranslator>REQUEST_PARSERSprivate static java.util.Map<java.lang.String,ProtobufTranslationImpl.ResponseTranslator>RESPONSE_PARSERSprivate java.lang.ThreadLocal<UnsynchronizedBuffer>threadLocalBuffer
-
Constructor Summary
Constructors Constructor Description ProtobufTranslationImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.util.List<java.lang.Class<?>>getAllMessageClasses()(package private) com.google.protobuf.ByteStringgetClassNameBytes(java.lang.Class<?> clz)static ProtobufTranslationImpl.RequestTranslatorgetParserForRequest(java.lang.String className)Fetches the concrete message's Parser implementation.static ProtobufTranslationImpl.ResponseTranslatorgetParserForResponse(java.lang.String className)Fetches the concrete message's Parser implementation.Service.RequestparseRequest(byte[] bytes)Parses a serialized protocol buffer request into aService.Request.Service.ResponseparseResponse(byte[] bytes)Parses a serialized protocol buffer response into aService.Response.(package private) voidserializeMessage(java.io.OutputStream out, com.google.protobuf.Message msg)byte[]serializeRequest(Service.Request request)Serializes aService.Requestas a protocol buffer.byte[]serializeResponse(Service.Response response)Serializes aService.Responseas a protocol buffer.private static com.google.protobuf.ByteStringwrapClassName(java.lang.Class<?> clz)
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
REQUEST_PARSERS
private static final java.util.Map<java.lang.String,ProtobufTranslationImpl.RequestTranslator> REQUEST_PARSERS
-
RESPONSE_PARSERS
private static final java.util.Map<java.lang.String,ProtobufTranslationImpl.ResponseTranslator> RESPONSE_PARSERS
-
MESSAGE_CLASSES
private static final java.util.Map<java.lang.Class<?>,com.google.protobuf.ByteString> MESSAGE_CLASSES
-
threadLocalBuffer
private final java.lang.ThreadLocal<UnsynchronizedBuffer> threadLocalBuffer
-
-
Method Detail
-
getAllMessageClasses
private static java.util.List<java.lang.Class<?>> getAllMessageClasses()
-
wrapClassName
private static com.google.protobuf.ByteString wrapClassName(java.lang.Class<?> clz)
-
getParserForRequest
public static ProtobufTranslationImpl.RequestTranslator getParserForRequest(java.lang.String className)
Fetches the concrete message's Parser implementation.- Parameters:
className- The protocol buffer class name- Returns:
- The Parser for the class
- Throws:
java.lang.IllegalArgumentException- If the argument is null or if a Parser for the given class name is not found.
-
getParserForResponse
public static ProtobufTranslationImpl.ResponseTranslator getParserForResponse(java.lang.String className)
Fetches the concrete message's Parser implementation.- Parameters:
className- The protocol buffer class name- Returns:
- The Parser for the class
- Throws:
java.lang.IllegalArgumentException- If the argument is null or if a Parser for the given class name is not found.
-
serializeResponse
public byte[] serializeResponse(Service.Response response) throws java.io.IOException
Description copied from interface:ProtobufTranslationSerializes aService.Responseas a protocol buffer.- Specified by:
serializeResponsein interfaceProtobufTranslation- Parameters:
response- The response to serialize- Throws:
java.io.IOException- If there are errors during serialization
-
serializeRequest
public byte[] serializeRequest(Service.Request request) throws java.io.IOException
Description copied from interface:ProtobufTranslationSerializes aService.Requestas a protocol buffer.- Specified by:
serializeRequestin interfaceProtobufTranslation- Parameters:
request- The request to serialize- Throws:
java.io.IOException- If there are errors during serialization
-
serializeMessage
void serializeMessage(java.io.OutputStream out, com.google.protobuf.Message msg) throws java.io.IOException- Throws:
java.io.IOException
-
getClassNameBytes
com.google.protobuf.ByteString getClassNameBytes(java.lang.Class<?> clz)
-
parseRequest
public Service.Request parseRequest(byte[] bytes) throws java.io.IOException
Description copied from interface:ProtobufTranslationParses a serialized protocol buffer request into aService.Request.- Specified by:
parseRequestin interfaceProtobufTranslation- Parameters:
bytes- Serialized protocol buffer request from client- Returns:
- A Request object for the given bytes
- Throws:
java.io.IOException- If the protocol buffer cannot be deserialized
-
parseResponse
public Service.Response parseResponse(byte[] bytes) throws java.io.IOException
Description copied from interface:ProtobufTranslationParses a serialized protocol buffer response into aService.Response.- Specified by:
parseResponsein interfaceProtobufTranslation- Parameters:
bytes- Serialized protocol buffer request from server- Returns:
- The Response object for the given bytes
- Throws:
java.io.IOException- If the protocol buffer cannot be deserialized
-
-