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.ExecutorService;
022import org.apache.hadoop.conf.Configuration;
023import org.apache.hadoop.hbase.ServerName;
024import org.apache.hadoop.hbase.TableName;
025import org.apache.yetus.audience.InterfaceAudience;
026
027/**
028 * Wraps a {@link Connection} to make it can't be closed or aborted.
029 */
030@InterfaceAudience.Private
031public class SharedConnection implements Connection {
032
033  private final Connection conn;
034
035  public SharedConnection(Connection conn) {
036    this.conn = conn;
037  }
038
039  @Override
040  public void close() throws IOException {
041    throw new UnsupportedOperationException("Shared connection");
042  }
043
044  @Override
045  public boolean isClosed() {
046    return this.conn.isClosed();
047  }
048
049  @Override
050  public void abort(String why, Throwable e) {
051    throw new UnsupportedOperationException("Shared connection");
052  }
053
054  @Override
055  public boolean isAborted() {
056    return this.conn.isAborted();
057  }
058
059  @Override
060  public Configuration getConfiguration() {
061    return this.conn.getConfiguration();
062  }
063
064  @Override
065  public BufferedMutator getBufferedMutator(TableName tableName) throws IOException {
066    return this.conn.getBufferedMutator(tableName);
067  }
068
069  @Override
070  public BufferedMutator getBufferedMutator(BufferedMutatorParams params) throws IOException {
071    return this.conn.getBufferedMutator(params);
072  }
073
074  @Override
075  public RegionLocator getRegionLocator(TableName tableName) throws IOException {
076    return this.conn.getRegionLocator(tableName);
077  }
078
079  @Override
080  public Admin getAdmin() throws IOException {
081    return this.conn.getAdmin();
082  }
083
084  @Override
085  public TableBuilder getTableBuilder(TableName tableName, ExecutorService pool) {
086    return this.conn.getTableBuilder(tableName, pool);
087  }
088
089  @Override
090  public void clearRegionLocationCache() {
091    conn.clearRegionLocationCache();
092  }
093
094  @Override
095  public Hbck getHbck() throws IOException {
096    return conn.getHbck();
097  }
098
099  @Override
100  public Hbck getHbck(ServerName masterServer) throws IOException {
101    return conn.getHbck(masterServer);
102  }
103
104  @Override
105  public AsyncConnection toAsyncConnection() {
106    return new SharedAsyncConnection(conn.toAsyncConnection());
107  }
108}