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