Class AbstractRpcClient<T extends RpcConnection>

java.lang.Object
org.apache.hadoop.hbase.ipc.AbstractRpcClient<T>
All Implemented Interfaces:
Closeable, AutoCloseable, RpcClient
Direct Known Subclasses:
BlockingRpcClient, NettyRpcClient

@Private public abstract class AbstractRpcClient<T extends RpcConnection> extends Object implements RpcClient
Provides the basics for a RpcClient implementation like configuration and Logging.

Locking schema of the current IPC implementation

Since:
2.0.0
  • Field Details

  • Constructor Details

    • AbstractRpcClient

      public AbstractRpcClient(org.apache.hadoop.conf.Configuration conf, String clusterId, SocketAddress localAddr, MetricsConnection metrics, Map<String,byte[]> connectionAttributes)
      Construct an IPC client for the cluster clusterId
      Parameters:
      conf - configuration
      clusterId - the cluster id
      localAddr - client socket bind address.
      metrics - the connection metrics
  • Method Details

    • cleanupIdleConnections

      private void cleanupIdleConnections()
    • getDefaultCodec

      public static String getDefaultCodec(org.apache.hadoop.conf.Configuration c)
    • getCodec

      protected Codec getCodec()
      Encapsulate the ugly casting and RuntimeException conversion in private method.
      Returns:
      Codec to use on this client.
    • hasCellBlockSupport

      public boolean hasCellBlockSupport()
      Description copied from interface: RpcClient
      Return true when this client uses a Codec and so supports cell blocks.
      Specified by:
      hasCellBlockSupport in interface RpcClient
    • isTcpNoDelay

      protected boolean isTcpNoDelay()
    • getCompressor

      private static org.apache.hadoop.io.compress.CompressionCodec getCompressor(org.apache.hadoop.conf.Configuration conf)
      Encapsulate the ugly casting and RuntimeException conversion in private method.
      Parameters:
      conf - configuration
      Returns:
      The compressor to use on this client.
    • getPoolType

      private static PoolMap.PoolType getPoolType(org.apache.hadoop.conf.Configuration config)
      Return the pool type specified in the configuration, which must be set to either PoolMap.PoolType.RoundRobin or PoolMap.PoolType.ThreadLocal, otherwise default to the former. For applications with many user threads, use a small round-robin pool. For applications with few user threads, you may want to try using a thread-local pool. In any case, the number of RpcClient instances should not exceed the operating system's hard limit on the number of connections.
      Parameters:
      config - configuration
      Returns:
      either a PoolMap.PoolType.RoundRobin or PoolMap.PoolType.ThreadLocal
    • getPoolSize

      private static int getPoolSize(org.apache.hadoop.conf.Configuration config)
      Return the pool size specified in the configuration, which is applicable only if the pool type is PoolMap.PoolType.RoundRobin.
      Parameters:
      config - configuration
      Returns:
      the maximum pool size
    • nextCallId

      private int nextCallId()
    • callBlockingMethod

      private org.apache.hbase.thirdparty.com.google.protobuf.Message callBlockingMethod(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor md, HBaseRpcController hrc, org.apache.hbase.thirdparty.com.google.protobuf.Message param, org.apache.hbase.thirdparty.com.google.protobuf.Message returnType, User ticket, Address isa) throws org.apache.hbase.thirdparty.com.google.protobuf.ServiceException
      Make a blocking call. Throws exceptions if there are network problems or if the remote code threw an exception.
      Parameters:
      ticket - Be careful which ticket you pass. A new user will mean a new Connection. UserProvider.getCurrent() makes a new instance of User each time so will be a new Connection each time.
      Returns:
      A pair with the Message response and the Cell data (if any).
      Throws:
      org.apache.hbase.thirdparty.com.google.protobuf.ServiceException
    • getConnection

      private T getConnection(ConnectionId remoteId) throws IOException
      Get a connection from the pool, or create a new one and add it to the pool. Connections to a given host/port are reused.
      Throws:
      IOException
    • createConnection

      protected abstract T createConnection(ConnectionId remoteId) throws IOException
      Not connected.
      Throws:
      IOException
    • onCallFinished

      private void onCallFinished(Call call, HBaseRpcController hrc, Address addr, org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback<org.apache.hbase.thirdparty.com.google.protobuf.Message> callback)
    • callMethod

      private Call callMethod(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor md, HBaseRpcController hrc, org.apache.hbase.thirdparty.com.google.protobuf.Message param, org.apache.hbase.thirdparty.com.google.protobuf.Message returnType, User ticket, Address addr, org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback<org.apache.hbase.thirdparty.com.google.protobuf.Message> callback)
    • createAddr

    • cancelConnections

      public void cancelConnections(ServerName sn)
      Interrupt the connections to the given ip:port server. This should be called if the server is known as actually dead. This will not prevent current operation to be retried, and, depending on their own behavior, they may retry on the same server. This can be a feature, for example at startup. In any case, they're likely to get connection refused (if the process died) or no route to host: i.e. their next retries should be faster and with a safe exception.
      Specified by:
      cancelConnections in interface RpcClient
      Parameters:
      sn - server location to cancel connections of
    • configureHBaseRpcController

      static HBaseRpcController configureHBaseRpcController(org.apache.hbase.thirdparty.com.google.protobuf.RpcController controller, int channelOperationTimeout)
      Configure an hbase rpccontroller
      Parameters:
      controller - to configure
      channelOperationTimeout - timeout for operation
      Returns:
      configured controller
    • closeInternal

      protected abstract void closeInternal()
    • close

      public void close()
      Description copied from interface: RpcClient
      Stop all threads related to this client. No further calls may be made using this client.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface RpcClient
    • createBlockingRpcChannel

      public org.apache.hbase.thirdparty.com.google.protobuf.BlockingRpcChannel createBlockingRpcChannel(ServerName sn, User ticket, int rpcTimeout)
      Description copied from interface: RpcClient
      Creates a "channel" that can be used by a blocking protobuf service. Useful setting up protobuf blocking stubs.
      Specified by:
      createBlockingRpcChannel in interface RpcClient
      Parameters:
      sn - server name describing location of server
      ticket - which is to use the connection
      rpcTimeout - default rpc operation timeout
      Returns:
      A blocking rpc channel that goes via this rpc client instance.
    • createRpcChannel

      public org.apache.hbase.thirdparty.com.google.protobuf.RpcChannel createRpcChannel(ServerName sn, User user, int rpcTimeout)
      Description copied from interface: RpcClient
      Creates a "channel" that can be used by a protobuf service. Useful setting up protobuf stubs.
      Specified by:
      createRpcChannel in interface RpcClient
      Parameters:
      sn - server name describing location of server
      user - which is to use the connection
      rpcTimeout - default rpc operation timeout
      Returns:
      A rpc channel that goes via this rpc client instance.
    • getConnections