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 java.io.IOException;
21 import java.net.SocketAddress;
22
23 import javax.net.SocketFactory;
24
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.hadoop.hbase.HConstants;
27 import org.apache.hadoop.hbase.classification.InterfaceAudience;
28 import org.apache.hadoop.hbase.client.MetricsConnection;
29 import org.apache.hadoop.net.NetUtils;
30
31 /**
32 * Does RPC against a cluster. Manages connections per regionserver in the cluster.
33 * <p>
34 * See HBaseServer
35 */
36 @InterfaceAudience.Private
37 public class BlockingRpcClient extends AbstractRpcClient<BlockingRpcConnection> {
38
39 protected final SocketFactory socketFactory; // how to create sockets
40
41 /**
42 * Used in test only. Construct an IPC client for the cluster {@code clusterId} with the default
43 * SocketFactory
44 */
45 BlockingRpcClient(Configuration conf) {
46 this(conf, HConstants.CLUSTER_ID_DEFAULT, null, null);
47 }
48
49 /**
50 * Construct an IPC client for the cluster {@code clusterId} with the default SocketFactory This
51 * method is called with reflection by the RpcClientFactory to create an instance
52 * @param conf configuration
53 * @param clusterId the cluster id
54 * @param localAddr client socket bind address.
55 * @param metrics the connection metrics
56 */
57 public BlockingRpcClient(Configuration conf, String clusterId, SocketAddress localAddr,
58 MetricsConnection metrics) {
59 super(conf, clusterId, localAddr, metrics);
60 this.socketFactory = NetUtils.getDefaultSocketFactory(conf);
61 }
62
63 /**
64 * Creates a connection. Can be overridden by a subclass for testing.
65 * @param remoteId - the ConnectionId to use for the connection creation.
66 */
67 @Override
68 protected BlockingRpcConnection createConnection(ConnectionId remoteId) throws IOException {
69 return new BlockingRpcConnection(this, remoteId);
70 }
71
72 @Override
73 protected void closeInternal() {
74 }
75 }