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.ipc;
019
020import java.io.Closeable;
021import org.apache.hadoop.hbase.ServerName;
022import org.apache.hadoop.hbase.security.User;
023import org.apache.yetus.audience.InterfaceAudience;
024
025import org.apache.hbase.thirdparty.com.google.protobuf.BlockingRpcChannel;
026import org.apache.hbase.thirdparty.com.google.protobuf.RpcChannel;
027
028/**
029 * Interface for RpcClient implementations so ConnectionManager can handle it.
030 */
031@InterfaceAudience.Private
032public interface RpcClient extends Closeable {
033  String FAILED_SERVER_EXPIRY_KEY = "hbase.ipc.client.failed.servers.expiry";
034  int FAILED_SERVER_EXPIRY_DEFAULT = 2000;
035  String IDLE_TIME = "hbase.ipc.client.connection.minIdleTimeBeforeClose";
036  String IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_KEY =
037    "hbase.ipc.client.fallback-to-simple-auth-allowed";
038  boolean IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_DEFAULT = false;
039  String SPECIFIC_WRITE_THREAD = "hbase.ipc.client.specificThreadForWriting";
040  String DEFAULT_CODEC_CLASS = "hbase.client.default.rpc.codec";
041
042  String SOCKET_TIMEOUT_CONNECT = "hbase.ipc.client.socket.timeout.connect";
043  /**
044   * How long we wait when we wait for an answer. It's not the operation time, it's the time we wait
045   * when we start to receive an answer, when the remote write starts to send the data.
046   */
047  String SOCKET_TIMEOUT_READ = "hbase.ipc.client.socket.timeout.read";
048  String SOCKET_TIMEOUT_WRITE = "hbase.ipc.client.socket.timeout.write";
049  int DEFAULT_SOCKET_TIMEOUT_CONNECT = 10000; // 10 seconds
050  int DEFAULT_SOCKET_TIMEOUT_READ = 20000; // 20 seconds
051  int DEFAULT_SOCKET_TIMEOUT_WRITE = 60000; // 60 seconds
052
053  // Used by the server, for compatibility with old clients.
054  // The client in 0.99+ does not ping the server.
055  int PING_CALL_ID = -1;
056
057  byte[] REGISTRY_PREAMBLE_HEADER = new byte[] { 'R', 'e', 'g', 'i', 's', 't' };
058
059  byte[] SECURITY_PREAMBLE_HEADER = new byte[] { 'S', 'e', 'c', 'u', 'r', 'i' };
060
061  /**
062   * Creates a "channel" that can be used by a blocking protobuf service. Useful setting up protobuf
063   * blocking stubs.
064   * @param sn         server name describing location of server
065   * @param user       which is to use the connection
066   * @param rpcTimeout default rpc operation timeout
067   * @return A blocking rpc channel that goes via this rpc client instance.
068   */
069  BlockingRpcChannel createBlockingRpcChannel(ServerName sn, User user, int rpcTimeout);
070
071  /**
072   * Creates a "channel" that can be used by a protobuf service. Useful setting up protobuf stubs.
073   * @param sn         server name describing location of server
074   * @param user       which is to use the connection
075   * @param rpcTimeout default rpc operation timeout
076   * @return A rpc channel that goes via this rpc client instance.
077   */
078  RpcChannel createRpcChannel(final ServerName sn, final User user, int rpcTimeout);
079
080  /**
081   * Interrupt the connections to the given server. This should be called if the server is known as
082   * actually dead. This will not prevent current operation to be retried, and, depending on their
083   * own behavior, they may retry on the same server. This can be a feature, for example at startup.
084   * In any case, they're likely to get connection refused (if the process died) or no route to
085   * host: i.e. their next retries should be faster and with a safe exception.
086   * @param sn server location to cancel connections of
087   */
088  void cancelConnections(ServerName sn);
089
090  /**
091   * Stop all threads related to this client. No further calls may be made using this client.
092   */
093  @Override
094  void close();
095
096  /**
097   * Return true when this client uses a {@link org.apache.hadoop.hbase.codec.Codec} and so supports
098   * cell blocks.
099   */
100  boolean hasCellBlockSupport();
101}