001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.client;
019
020import java.io.IOException;
021import org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel;
022import org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils;
023import org.apache.yetus.audience.InterfaceAudience;
024import org.slf4j.Logger;
025import org.slf4j.LoggerFactory;
026
027import org.apache.hbase.thirdparty.com.google.protobuf.Descriptors;
028import org.apache.hbase.thirdparty.com.google.protobuf.Message;
029import org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback;
030import org.apache.hbase.thirdparty.com.google.protobuf.RpcController;
031import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException;
032
033/**
034 * Base class which provides clients with an RPC connection to call coprocessor endpoint
035 * {@link com.google.protobuf.Service}s. Note that clients should not use this class directly,
036 * except through {@link org.apache.hadoop.hbase.client.Table#coprocessorService(byte[])}.
037 * @deprecated Please stop using this class again, as it is too low level, which is part of the rpc
038 *             framework for HBase. Will be deleted in 4.0.0.
039 */
040@Deprecated
041@InterfaceAudience.Public
042abstract class SyncCoprocessorRpcChannel implements CoprocessorRpcChannel {
043  private static final Logger LOG = LoggerFactory.getLogger(SyncCoprocessorRpcChannel.class);
044
045  @Override
046  @InterfaceAudience.Private
047  public void callMethod(Descriptors.MethodDescriptor method, RpcController controller,
048    Message request, Message responsePrototype, RpcCallback<Message> callback) {
049    Message response = null;
050    try {
051      response = callExecService(controller, method, request, responsePrototype);
052    } catch (IOException ioe) {
053      LOG.warn("Call failed on IOException", ioe);
054      CoprocessorRpcUtils.setControllerException(controller, ioe);
055    }
056    if (callback != null) {
057      callback.run(response);
058    }
059  }
060
061  @Override
062  @InterfaceAudience.Private
063  public Message callBlockingMethod(Descriptors.MethodDescriptor method, RpcController controller,
064    Message request, Message responsePrototype) throws ServiceException {
065    try {
066      return callExecService(controller, method, request, responsePrototype);
067    } catch (IOException ioe) {
068      throw new ServiceException("Error calling method " + method.getFullName(), ioe);
069    }
070  }
071
072  protected abstract Message callExecService(RpcController controller,
073    Descriptors.MethodDescriptor method, Message request, Message responsePrototype)
074    throws IOException;
075}