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