Search in sources :

Example 1 with CustomResponse

use of org.apache.drill.exec.rpc.control.Controller.CustomResponse in project drill by apache.

the class CustomHandlerRegistry method handle.

public Response handle(CustomMessage message, DrillBuf dBody) throws RpcException {
    final ParsingHandler<?, ?> handler;
    try (AutoCloseableLock lock = read.open()) {
        handler = handlers.get(message.getType());
    }
    if (handler == null) {
        throw new UserRpcException(endpoint, "Unable to handle message.", new IllegalStateException(String.format("Unable to handle message. The message type provided [%d] did not have a registered handler.", message.getType())));
    }
    final CustomResponse<?> customResponse = handler.onMessage(message.getMessage(), dBody);
    @SuppressWarnings("unchecked") final CustomMessage responseMessage = CustomMessage.newBuilder().setMessage(ByteString.copyFrom(((Controller.CustomSerDe<Object>) handler.getResponseSerDe()).serializeToSend(customResponse.getMessage()))).setType(message.getType()).build();
    // make sure we don't pass in a null array.
    final ByteBuf[] dBodies = customResponse.getBodies() == null ? new DrillBuf[0] : customResponse.getBodies();
    return new Response(RpcType.RESP_CUSTOM, responseMessage, dBodies);
}
Also used : Response(org.apache.drill.exec.rpc.Response) CustomResponse(org.apache.drill.exec.rpc.control.Controller.CustomResponse) UserRpcException(org.apache.drill.exec.rpc.UserRpcException) AutoCloseableLock(org.apache.drill.common.concurrent.AutoCloseableLock) CustomMessage(org.apache.drill.exec.proto.BitControl.CustomMessage) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)1 AutoCloseableLock (org.apache.drill.common.concurrent.AutoCloseableLock)1 CustomMessage (org.apache.drill.exec.proto.BitControl.CustomMessage)1 Response (org.apache.drill.exec.rpc.Response)1 UserRpcException (org.apache.drill.exec.rpc.UserRpcException)1 CustomResponse (org.apache.drill.exec.rpc.control.Controller.CustomResponse)1