org.apache.calcite.avatica.remote

## Class AbstractHandler<T>

- java.lang.Object
- - org.apache.calcite.avatica.remote.AbstractHandler<T>

Type Parameters:
  `T` - The format Requests/Responses are serialized as.

All Implemented Interfaces:
  Handler<T>

Direct Known Subclasses:
  JsonHandler, ProtobufHandler

    public abstract class AbstractHandler<T>
    extends Object
    implements Handler<T>

Abstract base class for `Handler`s to extend to inherit functionality common across serialization strategies.

### Nested Class Summary

### Nested classes/interfaces inherited from interface org.apache.calcite.avatica.remote.Handler

`Handler.HandlerResponse<T>`

### Field Summary

Fields
`private Service.RpcMetadataResponse` `metadata`
`private static String` `NULL_EXCEPTION_MESSAGE`
`protected Service` `service`

### Fields inherited from interface org.apache.calcite.avatica.remote.Handler

`HANDLER_SERIALIZATION_METRICS_NAME, HTTP_INTERNAL_SERVER_ERROR, HTTP_OK`

### Constructor Summary

Constructors
Constructor and Description
`AbstractHandler(Service service)`

### Method Summary

Methods
`Handler.HandlerResponse<T>` `apply(T serializedRequest)` Compute a response for the given request, handling errors generated by that computation.
`Handler.HandlerResponse<T>` `convertToErrorResponse(Exception e)` Attempts to convert an Exception to an ErrorResponse.
`(package private) abstract Service.Request` `decode(T serializedRequest)`
`(package private) abstract T` `encode(Service.Response response)` Serialize the given `Service.Response` per the concrete `Handler` implementation.
`private String` `getCausalChain(Exception e)` Constructs a message for the summary of an Exception.
`void` `setRpcMetadata(Service.RpcMetadataResponse metadata)` Sets some general server information to return to the client in all responses.
`(package private) Service.ErrorResponse` `unwrapException(Exception e)` Unwrap Avatica-specific context about a given exception.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### NULL_EXCEPTION_MESSAGE

    private static final String NULL_EXCEPTION_MESSAGE

See Also:
  Constant Field Values

#### service

    protected final Service service

#### metadata

    private Service.RpcMetadataResponse metadata

### Constructor Detail

#### AbstractHandler

    public AbstractHandler(Service service)

### Method Detail

#### decode

    abstract Service.Request decode(T serializedRequest)
                             throws IOException

Throws:
  `IOException`

#### encode

    abstract T encode(Service.Response response)
               throws IOException

Serialize the given `Service.Response` per the concrete `Handler` implementation.

Parameters:
  `response` - The `Service.Response` to serialize.
Returns:
  A serialized representation of the `Service.Response`.
Throws:
  `IOException`

#### unwrapException

    Service.ErrorResponse unwrapException(Exception e)

Unwrap Avatica-specific context about a given exception.

Parameters:
  `e` - A caught exception throw by Avatica implementation.
Returns:
  An `Service.ErrorResponse`.

#### apply

    public Handler.HandlerResponse<T> apply(T serializedRequest)

Compute a response for the given request, handling errors generated by that computation.

Specified by:
  `apply` in interface `Handler<T>`
Parameters:
  `serializedRequest` - The caller's request.
Returns:
  A `Service.Response` with additional context about that response.

#### convertToErrorResponse

    public Handler.HandlerResponse<T> convertToErrorResponse(Exception e)

Attempts to convert an Exception to an ErrorResponse. If there is an issue in serialization, a RuntimeException is thrown instead (wrapping the original exception if necessary).

Parameters:
  `e` - The exception to convert.
Returns:
  A HandlerResponse instance.

#### getCausalChain

    private String getCausalChain(Exception e)

Constructs a message for the summary of an Exception.

Parameters:
  `e` - The Exception to summarize.
Returns:
  A summary message for the Exception.

#### setRpcMetadata

    public void setRpcMetadata(Service.RpcMetadataResponse metadata)

Description copied from interface: `Handler`
Sets some general server information to return to the client in all responses.

Specified by:
  `setRpcMetadata` in interface `Handler<T>`
Parameters:
  `metadata` - Server-wide information