001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.client;
019
020import java.io.IOException;
021import java.util.concurrent.CompletableFuture;
022import java.util.concurrent.ExecutorService;
023import org.apache.hadoop.conf.Configuration;
024import org.apache.hadoop.hbase.ServerName;
025import org.apache.hadoop.hbase.TableName;
026import org.apache.yetus.audience.InterfaceAudience;
027
028/**
029 * Wraps a {@link AsyncConnection} to make it can't be closed.
030 */
031@InterfaceAudience.Private
032public class SharedAsyncConnection implements AsyncConnection {
033
034  private final AsyncConnection conn;
035
036  public SharedAsyncConnection(AsyncConnection conn) {
037    this.conn = conn;
038  }
039
040  @Override
041  public boolean isClosed() {
042    return conn.isClosed();
043  }
044
045  @Override
046  public void close() throws IOException {
047    throw new UnsupportedOperationException("Shared connection");
048  }
049
050  @Override
051  public Configuration getConfiguration() {
052    return conn.getConfiguration();
053  }
054
055  @Override
056  public AsyncTableRegionLocator getRegionLocator(TableName tableName) {
057    return conn.getRegionLocator(tableName);
058  }
059
060  @Override
061  public void clearRegionLocationCache() {
062    conn.clearRegionLocationCache();
063  }
064
065  @Override
066  public AsyncTableBuilder<AdvancedScanResultConsumer> getTableBuilder(TableName tableName) {
067    return conn.getTableBuilder(tableName);
068  }
069
070  @Override
071  public AsyncTableBuilder<ScanResultConsumer> getTableBuilder(TableName tableName,
072    ExecutorService pool) {
073    return conn.getTableBuilder(tableName, pool);
074  }
075
076  @Override
077  public AsyncAdminBuilder getAdminBuilder() {
078    return conn.getAdminBuilder();
079  }
080
081  @Override
082  public AsyncAdminBuilder getAdminBuilder(ExecutorService pool) {
083    return conn.getAdminBuilder(pool);
084  }
085
086  @Override
087  public AsyncBufferedMutatorBuilder getBufferedMutatorBuilder(TableName tableName) {
088    return conn.getBufferedMutatorBuilder(tableName);
089  }
090
091  @Override
092  public AsyncBufferedMutatorBuilder getBufferedMutatorBuilder(TableName tableName,
093    ExecutorService pool) {
094    return conn.getBufferedMutatorBuilder(tableName, pool);
095  }
096
097  @Override
098  public CompletableFuture<Hbck> getHbck() {
099    return conn.getHbck();
100  }
101
102  @Override
103  public Hbck getHbck(ServerName masterServer) throws IOException {
104    return conn.getHbck(masterServer);
105  }
106
107  @Override
108  public Connection toConnection() {
109    return new SharedConnection(conn.toConnection());
110  }
111
112}