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