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 org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
021
022import java.io.IOException;
023import java.net.SocketAddress;
024
025import javax.net.SocketFactory;
026
027import org.apache.hadoop.conf.Configuration;
028import org.apache.hadoop.hbase.HConstants;
029import org.apache.yetus.audience.InterfaceAudience;
030import org.apache.hadoop.hbase.client.MetricsConnection;
031import org.apache.hadoop.net.NetUtils;
032
033/**
034 * Does RPC against a cluster. Manages connections per regionserver in the cluster.
035 * <p>
036 * See HBaseServer
037 */
038@InterfaceAudience.Private
039public class BlockingRpcClient extends AbstractRpcClient<BlockingRpcConnection> {
040
041  protected final SocketFactory socketFactory; // how to create sockets
042
043  /**
044   * Used in test only. Construct an IPC client for the cluster {@code clusterId} with the default
045   * SocketFactory
046   */
047  @VisibleForTesting
048  BlockingRpcClient(Configuration conf) {
049    this(conf, HConstants.CLUSTER_ID_DEFAULT, null, null);
050  }
051
052  /**
053   * Construct an IPC client for the cluster {@code clusterId} with the default SocketFactory This
054   * method is called with reflection by the RpcClientFactory to create an instance
055   * @param conf configuration
056   * @param clusterId the cluster id
057   * @param localAddr client socket bind address.
058   * @param metrics the connection metrics
059   */
060  public BlockingRpcClient(Configuration conf, String clusterId, SocketAddress localAddr,
061      MetricsConnection metrics) {
062    super(conf, clusterId, localAddr, metrics);
063    this.socketFactory = NetUtils.getDefaultSocketFactory(conf);
064  }
065
066  /**
067   * Creates a connection. Can be overridden by a subclass for testing.
068   * @param remoteId - the ConnectionId to use for the connection creation.
069   */
070  @Override
071  protected BlockingRpcConnection createConnection(ConnectionId remoteId) throws IOException {
072    return new BlockingRpcConnection(this, remoteId);
073  }
074
075  @Override
076  protected void closeInternal() {
077  }
078}