1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.client;
19
20 import java.io.IOException;
21
22 import org.apache.hadoop.hbase.classification.InterfaceAudience;
23 import org.apache.hadoop.hbase.classification.InterfaceStability;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.CoprocessorEnvironment;
26 import org.apache.hadoop.hbase.ServerName;
27 import org.apache.hadoop.hbase.client.ConnectionManager.HConnectionImplementation;
28 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
29 import org.apache.hadoop.hbase.regionserver.HRegionServer;
30 import org.apache.hadoop.hbase.regionserver.RegionServerServices;
31 import org.apache.hadoop.hbase.security.UserProvider;
32
33
34
35
36
37
38
39
40
41 @InterfaceAudience.Private
42 @InterfaceStability.Evolving
43 public class CoprocessorHConnection extends HConnectionImplementation {
44 private static final NonceGenerator NO_NONCE_GEN = new ConnectionManager.NoNonceGenerator();
45
46
47
48
49
50
51
52
53
54 public static ClusterConnection getConnectionForEnvironment(CoprocessorEnvironment env)
55 throws IOException {
56
57 if (env instanceof RegionCoprocessorEnvironment) {
58 RegionCoprocessorEnvironment e = (RegionCoprocessorEnvironment) env;
59 RegionServerServices services = e.getRegionServerServices();
60 if (services instanceof HRegionServer) {
61 return new CoprocessorHConnection((HRegionServer) services);
62 }
63 }
64 return ConnectionManager.createConnectionInternal(env.getConfiguration());
65 }
66
67 private final ServerName serverName;
68 private final HRegionServer server;
69
70
71
72
73
74
75
76
77 @Deprecated
78 public CoprocessorHConnection(ClusterConnection delegate, HRegionServer server)
79 throws IOException {
80 this(server);
81 }
82
83
84
85
86
87
88 public CoprocessorHConnection(HRegionServer server) throws IOException {
89 this(server.getConfiguration(), server);
90 }
91
92
93
94
95
96
97
98 public CoprocessorHConnection(Configuration conf, HRegionServer server) throws IOException {
99 super(conf, false, null, UserProvider.instantiate(conf).getCurrent());
100 this.server = server;
101 this.serverName = server.getServerName();
102 }
103
104 @Override
105 public org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ClientService.BlockingInterface
106 getClient(ServerName serverName) throws IOException {
107
108 if (!this.serverName.equals(serverName)) {
109 return super.getClient(serverName);
110 }
111
112
113 return server.getRSRpcServices();
114 }
115
116 @Override
117 public NonceGenerator getNonceGenerator() {
118 return NO_NONCE_GEN;
119 }
120 }