1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.hadoop.hbase.ipc;
19
20 import com.google.common.annotations.VisibleForTesting;
21
22 import java.io.IOException;
23 import java.net.SocketAddress;
24
25 import javax.net.SocketFactory;
26
27 import org.apache.hadoop.conf.Configuration;
28 import org.apache.hadoop.hbase.HConstants;
29 import org.apache.hadoop.hbase.classification.InterfaceAudience;
30 import org.apache.hadoop.hbase.client.MetricsConnection;
31 import org.apache.hadoop.net.NetUtils;
32
33 /**
34 * Does RPC against a cluster. Manages connections per regionserver in the cluster.
35 * <p>
36 * See HBaseServer
37 */
38 @InterfaceAudience.Private
39 public class BlockingRpcClient extends AbstractRpcClient<BlockingRpcConnection> {
40
41 protected final SocketFactory socketFactory; // how to create sockets
42
43 /**
44 * Used in test only. Construct an IPC client for the cluster {@code clusterId} with the default
45 * SocketFactory
46 */
47 @VisibleForTesting
48 BlockingRpcClient(Configuration conf) {
49 this(conf, HConstants.CLUSTER_ID_DEFAULT, null, null);
50 }
51
52 /**
53 * Construct an IPC client for the cluster {@code clusterId} with the default SocketFactory This
54 * method is called with reflection by the RpcClientFactory to create an instance
55 * @param conf configuration
56 * @param clusterId the cluster id
57 * @param localAddr client socket bind address.
58 * @param metrics the connection metrics
59 */
60 public BlockingRpcClient(Configuration conf, String clusterId, SocketAddress localAddr,
61 MetricsConnection metrics) {
62 super(conf, clusterId, localAddr, metrics);
63 this.socketFactory = NetUtils.getDefaultSocketFactory(conf);
64 }
65
66 /**
67 * Creates a connection. Can be overridden by a subclass for testing.
68 * @param remoteId - the ConnectionId to use for the connection creation.
69 */
70 @Override
71 protected BlockingRpcConnection createConnection(ConnectionId remoteId) throws IOException {
72 return new BlockingRpcConnection(this, remoteId);
73 }
74
75 @Override
76 protected void closeInternal() {
77 }
78 }