View Javadoc

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.client;
19  
20  import java.io.IOException;
21  import java.util.List;
22  import java.util.concurrent.ExecutorService;
23  
24  import org.apache.hadoop.conf.Configuration;
25  import org.apache.hadoop.hbase.HRegionLocation;
26  import org.apache.hadoop.hbase.HTableDescriptor;
27  import org.apache.hadoop.hbase.MasterNotRunningException;
28  import org.apache.hadoop.hbase.RegionLocations;
29  import org.apache.hadoop.hbase.ServerName;
30  import org.apache.hadoop.hbase.TableName;
31  import org.apache.hadoop.hbase.ZooKeeperConnectionException;
32  import org.apache.hadoop.hbase.classification.InterfaceAudience;
33  import org.apache.hadoop.hbase.client.backoff.ClientBackoffPolicy;
34  import org.apache.hadoop.hbase.client.coprocessor.Batch.Callback;
35  import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.AdminService;
36  import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ClientService;
37  import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.MasterService;
38  import org.apache.hadoop.hbase.ipc.RpcControllerFactory;
39  
40  /**
41   * An internal class that delegates to an {@link HConnection} instance.
42   * A convenience to override when customizing method implementations.
43   *
44   *
45   * @see ConnectionUtils#createShortCircuitHConnection(HConnection, ServerName,
46   * AdminService.BlockingInterface, ClientService.BlockingInterface) for case where we make
47   * Connections skip RPC if request is to local server.
48   */
49  @InterfaceAudience.Private
50  @Deprecated
51  //NOTE: DO NOT make this class public. It was made package-private on purpose.
52  abstract class ConnectionAdapter implements ClusterConnection {
53  
54    private final ClusterConnection wrappedConnection;
55  
56    public ConnectionAdapter(Connection c) {
57      wrappedConnection = (ClusterConnection)c;
58    }
59  
60    @Override
61    public void abort(String why, Throwable e) {
62      wrappedConnection.abort(why, e);
63    }
64  
65    @Override
66    public boolean isAborted() {
67      return wrappedConnection.isAborted();
68    }
69  
70    @Override
71    public void close() throws IOException {
72      wrappedConnection.close();
73    }
74  
75    @Override
76    public Configuration getConfiguration() {
77      return wrappedConnection.getConfiguration();
78    }
79  
80    @Override
81    public HTableInterface getTable(String tableName) throws IOException {
82      return wrappedConnection.getTable(tableName);
83    }
84  
85    @Override
86    public HTableInterface getTable(byte[] tableName) throws IOException {
87      return wrappedConnection.getTable(tableName);
88    }
89  
90    @Override
91    public HTableInterface getTable(TableName tableName) throws IOException {
92      return wrappedConnection.getTable(tableName);
93    }
94  
95    @Override
96    public HTableInterface getTable(String tableName, ExecutorService pool)
97        throws IOException {
98      return wrappedConnection.getTable(tableName, pool);
99    }
100 
101   @Override
102   public HTableInterface getTable(byte[] tableName, ExecutorService pool)
103       throws IOException {
104     return wrappedConnection.getTable(tableName, pool);
105   }
106 
107   @Override
108   public HTableInterface getTable(TableName tableName, ExecutorService pool)
109       throws IOException {
110     return wrappedConnection.getTable(tableName, pool);
111   }
112 
113   @Override
114   public BufferedMutator getBufferedMutator(BufferedMutatorParams params)
115       throws IOException {
116     return wrappedConnection.getBufferedMutator(params);
117   }
118 
119   @Override
120   public BufferedMutator getBufferedMutator(TableName tableName) throws IOException {
121     return wrappedConnection.getBufferedMutator(tableName);
122   }
123 
124   @Override
125   public RegionLocator getRegionLocator(TableName tableName) throws IOException {
126     return wrappedConnection.getRegionLocator(tableName);
127   }
128 
129   @Override
130   public Admin getAdmin() throws IOException {
131     return wrappedConnection.getAdmin();
132   }
133 
134   @Override
135   public boolean isMasterRunning() throws MasterNotRunningException,
136       ZooKeeperConnectionException {
137     return wrappedConnection.isMasterRunning();
138   }
139 
140   @Override
141   public boolean isTableEnabled(TableName tableName) throws IOException {
142     return wrappedConnection.isTableEnabled(tableName);
143   }
144 
145   @Override
146   public boolean isTableEnabled(byte[] tableName) throws IOException {
147     return wrappedConnection.isTableEnabled(tableName);
148   }
149 
150   @Override
151   public boolean isTableDisabled(TableName tableName) throws IOException {
152     return wrappedConnection.isTableDisabled(tableName);
153   }
154 
155   @Override
156   public boolean isTableDisabled(byte[] tableName) throws IOException {
157     return wrappedConnection.isTableDisabled(tableName);
158   }
159 
160   @Override
161   public boolean isTableAvailable(TableName tableName) throws IOException {
162     return wrappedConnection.isTableAvailable(tableName);
163   }
164 
165   @Override
166   public boolean isTableAvailable(byte[] tableName) throws IOException {
167     return wrappedConnection.isTableAvailable(tableName);
168   }
169 
170   @Override
171   public boolean isTableAvailable(TableName tableName, byte[][] splitKeys)
172       throws IOException {
173     return wrappedConnection.isTableAvailable(tableName, splitKeys);
174   }
175 
176   @Override
177   public boolean isTableAvailable(byte[] tableName, byte[][] splitKeys)
178       throws IOException {
179     return wrappedConnection.isTableAvailable(tableName, splitKeys);
180   }
181 
182   @Override
183   public HTableDescriptor[] listTables() throws IOException {
184     return wrappedConnection.listTables();
185   }
186 
187   @Override
188   public String[] getTableNames() throws IOException {
189     return wrappedConnection.getTableNames();
190   }
191 
192   @Override
193   public TableName[] listTableNames() throws IOException {
194     return wrappedConnection.listTableNames();
195   }
196 
197   @Override
198   public HTableDescriptor getHTableDescriptor(TableName tableName)
199       throws IOException {
200     return wrappedConnection.getHTableDescriptor(tableName);
201   }
202 
203   @Override
204   public HTableDescriptor getHTableDescriptor(byte[] tableName)
205       throws IOException {
206     return wrappedConnection.getHTableDescriptor(tableName);
207   }
208 
209   @Override
210   public HRegionLocation locateRegion(TableName tableName, byte[] row)
211       throws IOException {
212     return wrappedConnection.locateRegion(tableName, row);
213   }
214 
215   @Override
216   public HRegionLocation locateRegion(byte[] tableName, byte[] row)
217       throws IOException {
218     return wrappedConnection.locateRegion(tableName, row);
219   }
220 
221   @Override
222   public RegionLocations locateRegion(TableName tableName, byte[] row, boolean useCache,
223       boolean retry) throws IOException {
224     return wrappedConnection.locateRegion(tableName, row, useCache, retry);
225   }
226 
227   @Override
228   public void clearRegionCache() {
229     wrappedConnection.clearRegionCache();
230   }
231 
232   @Override
233   public void clearRegionCache(TableName tableName) {
234     wrappedConnection.clearRegionCache(tableName);
235   }
236 
237   @Override
238   public void clearRegionCache(byte[] tableName) {
239     wrappedConnection.clearRegionCache(tableName);
240   }
241 
242 
243   @Override
244   public void cacheLocation(TableName tableName, RegionLocations location) {
245     wrappedConnection.cacheLocation(tableName, location);
246   }
247 
248   @Override
249   public void deleteCachedRegionLocation(HRegionLocation location) {
250     wrappedConnection.deleteCachedRegionLocation(location);
251   }
252 
253   @Override
254   public HRegionLocation relocateRegion(TableName tableName, byte[] row)
255       throws IOException {
256     return wrappedConnection.relocateRegion(tableName, row);
257   }
258 
259   @Override
260   public HRegionLocation relocateRegion(byte[] tableName, byte[] row)
261       throws IOException {
262     return wrappedConnection.relocateRegion(tableName, row);
263   }
264 
265   @Override
266   public void updateCachedLocations(TableName tableName, byte[] rowkey,
267       Object exception, HRegionLocation source) {
268     wrappedConnection.updateCachedLocations(tableName, rowkey, exception, source);
269   }
270 
271   @Override
272   public void updateCachedLocations(TableName tableName, byte[] regionName, byte[] rowkey,
273       Object exception, ServerName source) {
274     wrappedConnection.updateCachedLocations(tableName, regionName, rowkey, exception, source);
275   }
276 
277   @Override
278   public void updateCachedLocations(byte[] tableName, byte[] rowkey,
279       Object exception, HRegionLocation source) {
280     wrappedConnection.updateCachedLocations(tableName, rowkey, exception, source);
281   }
282 
283   @Override
284   public HRegionLocation locateRegion(byte[] regionName) throws IOException {
285     return wrappedConnection.locateRegion(regionName);
286   }
287 
288   @Override
289   public List<HRegionLocation> locateRegions(TableName tableName)
290       throws IOException {
291     return wrappedConnection.locateRegions(tableName);
292   }
293 
294   @Override
295   public List<HRegionLocation> locateRegions(byte[] tableName)
296       throws IOException {
297     return wrappedConnection.locateRegions(tableName);
298   }
299 
300   @Override
301   public List<HRegionLocation> locateRegions(TableName tableName,
302       boolean useCache, boolean offlined) throws IOException {
303     return wrappedConnection.locateRegions(tableName, useCache, offlined);
304   }
305 
306   @Override
307   public List<HRegionLocation> locateRegions(byte[] tableName,
308       boolean useCache, boolean offlined) throws IOException {
309     return wrappedConnection.locateRegions(tableName, useCache, offlined);
310   }
311 
312   @Override
313   public RegionLocations locateRegion(TableName tableName, byte[] row, boolean useCache,
314       boolean retry, int replicaId) throws IOException {
315     return wrappedConnection.locateRegion(tableName, row, useCache, retry, replicaId);
316   }
317 
318   @Override
319   public RegionLocations relocateRegion(TableName tableName, byte[] row, int replicaId)
320       throws IOException {
321     return wrappedConnection.relocateRegion(tableName, row, replicaId);
322   }
323 
324   @Override
325   public MasterService.BlockingInterface getMaster() throws IOException {
326     return wrappedConnection.getMaster();
327   }
328 
329   @Override
330   public AdminService.BlockingInterface getAdmin(
331       ServerName serverName) throws IOException {
332     return wrappedConnection.getAdmin(serverName);
333   }
334 
335   @Override
336   public ClientService.BlockingInterface getClient(
337       ServerName serverName) throws IOException {
338     return wrappedConnection.getClient(serverName);
339   }
340 
341   @Override
342   public AdminService.BlockingInterface getAdmin(
343       ServerName serverName, boolean getMaster) throws IOException {
344     return wrappedConnection.getAdmin(serverName, getMaster);
345   }
346 
347   @Override
348   public HRegionLocation getRegionLocation(TableName tableName, byte[] row,
349       boolean reload) throws IOException {
350     return wrappedConnection.getRegionLocation(tableName, row, reload);
351   }
352 
353   @Override
354   public HRegionLocation getRegionLocation(byte[] tableName, byte[] row,
355       boolean reload) throws IOException {
356     return wrappedConnection.getRegionLocation(tableName, row, reload);
357   }
358 
359   @Override
360   public void processBatch(List<? extends Row> actions, TableName tableName,
361       ExecutorService pool, Object[] results) throws IOException,
362       InterruptedException {
363     wrappedConnection.processBatch(actions, tableName, pool, results);
364   }
365 
366   @Override
367   public void processBatch(List<? extends Row> actions, byte[] tableName,
368       ExecutorService pool, Object[] results) throws IOException,
369       InterruptedException {
370     wrappedConnection.processBatch(actions, tableName, pool, results);
371   }
372 
373   @Override
374   public <R> void processBatchCallback(List<? extends Row> list,
375       TableName tableName, ExecutorService pool, Object[] results,
376       Callback<R> callback) throws IOException, InterruptedException {
377     wrappedConnection.processBatchCallback(list, tableName, pool, results, callback);
378   }
379 
380   @Override
381   public <R> void processBatchCallback(List<? extends Row> list,
382       byte[] tableName, ExecutorService pool, Object[] results,
383       Callback<R> callback) throws IOException, InterruptedException {
384     wrappedConnection.processBatchCallback(list, tableName, pool, results, callback);
385   }
386 
387   @Override
388   public void setRegionCachePrefetch(TableName tableName, boolean enable) {
389     wrappedConnection.setRegionCachePrefetch(tableName, enable);
390   }
391 
392   @Override
393   public void setRegionCachePrefetch(byte[] tableName, boolean enable) {
394     wrappedConnection.setRegionCachePrefetch(tableName, enable);
395   }
396 
397   @Override
398   public boolean getRegionCachePrefetch(TableName tableName) {
399     return wrappedConnection.getRegionCachePrefetch(tableName);
400   }
401 
402   @Override
403   public boolean getRegionCachePrefetch(byte[] tableName) {
404      return wrappedConnection.getRegionCachePrefetch(tableName);
405   }
406 
407   @Override
408   public int getCurrentNrHRS() throws IOException {
409     return wrappedConnection.getCurrentNrHRS();
410   }
411 
412   @Override
413   public HTableDescriptor[] getHTableDescriptorsByTableName(
414       List<TableName> tableNames) throws IOException {
415     return wrappedConnection.getHTableDescriptorsByTableName(tableNames);
416   }
417 
418   @Override
419   public HTableDescriptor[] getHTableDescriptors(List<String> tableNames)
420       throws IOException {
421     return wrappedConnection.getHTableDescriptors(tableNames);
422   }
423 
424   @Override
425   public boolean isClosed() {
426     return wrappedConnection.isClosed();
427   }
428 
429   @Override
430   public void clearCaches(ServerName sn) {
431     wrappedConnection.clearCaches(sn);
432   }
433 
434   @Override
435   public MasterKeepAliveConnection getKeepAliveMasterService()
436       throws MasterNotRunningException {
437     return wrappedConnection.getKeepAliveMasterService();
438   }
439 
440   @Override
441   public boolean isDeadServer(ServerName serverName) {
442     return wrappedConnection.isDeadServer(serverName);
443   }
444 
445   @Override
446   public NonceGenerator getNonceGenerator() {
447     return wrappedConnection.getNonceGenerator();
448   }
449 
450   @Override
451   public AsyncProcess getAsyncProcess() {
452     return wrappedConnection.getAsyncProcess();
453   }
454 
455   @Override
456   public RpcRetryingCallerFactory getNewRpcRetryingCallerFactory(Configuration conf) {
457     return wrappedConnection.getNewRpcRetryingCallerFactory(conf);
458   }
459   
460   @Override
461   public boolean isManaged() {
462     return wrappedConnection.isManaged();
463   }
464 
465   @Override
466   public ServerStatisticTracker getStatisticsTracker() {
467     return wrappedConnection.getStatisticsTracker();
468   }
469 
470   @Override
471   public ClientBackoffPolicy getBackoffPolicy() {
472     return wrappedConnection.getBackoffPolicy();
473   }
474 
475   @Override
476   public boolean hasCellBlockSupport() {
477     return wrappedConnection.hasCellBlockSupport();
478   }
479   
480   @Override
481   public ConnectionConfiguration getConnectionConfiguration() {
482     return wrappedConnection.getConnectionConfiguration();
483   }
484 
485   @Override
486   public RpcRetryingCallerFactory getRpcRetryingCallerFactory() {
487     return wrappedConnection.getRpcRetryingCallerFactory();
488   }
489 
490   @Override
491   public RpcControllerFactory getRpcControllerFactory() {
492     return wrappedConnection.getRpcControllerFactory();
493   }
494 }