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.Closeable;
021import java.util.concurrent.ExecutorService;
022
023import org.apache.hadoop.conf.Configuration;
024import org.apache.hadoop.hbase.TableName;
025import org.apache.yetus.audience.InterfaceAudience;
026
027/**
028 * The asynchronous version of Connection.
029 * @since 2.0.0
030 */
031@InterfaceAudience.Public
032public interface AsyncConnection extends Closeable {
033
034  /**
035   * Returns the {@link org.apache.hadoop.conf.Configuration} object used by this instance.
036   * <p>
037   * The reference returned is not a copy, so any change made to it will affect this instance.
038   */
039  Configuration getConfiguration();
040
041  /**
042   * Retrieve a AsyncRegionLocator implementation to inspect region information on a table. The
043   * returned AsyncRegionLocator is not thread-safe, so a new instance should be created for each
044   * using thread. This is a lightweight operation. Pooling or caching of the returned
045   * AsyncRegionLocator is neither required nor desired.
046   * @param tableName Name of the table who's region is to be examined
047   * @return An AsyncRegionLocator instance
048   */
049  AsyncTableRegionLocator getRegionLocator(TableName tableName);
050
051  /**
052   * Retrieve an {@link AsyncTable} implementation for accessing a table.
053   * <p>
054   * The returned instance will use default configs. Use {@link #getTableBuilder(TableName)} if
055   * you want to customize some configs.
056   * <p>
057   * This method no longer checks table existence. An exception will be thrown if the table does not
058   * exist only when the first operation is attempted.
059   * <p>
060   * The returned {@code CompletableFuture} will be finished directly in the rpc framework's
061   * callback thread, so typically you should not do any time consuming work inside these methods.
062   * And also the observer style scan API will use {@link AdvancedScanResultConsumer} which is
063   * designed for experts only. Only use it when you know what you are doing.
064   * @param tableName the name of the table
065   * @return an AsyncTable to use for interactions with this table
066   * @see #getTableBuilder(TableName)
067   */
068  default AsyncTable<AdvancedScanResultConsumer> getTable(TableName tableName) {
069    return getTableBuilder(tableName).build();
070  }
071
072  /**
073   * Returns an {@link AsyncTableBuilder} for creating {@link AsyncTable}.
074   * <p>
075   * This method no longer checks table existence. An exception will be thrown if the table does not
076   * exist only when the first operation is attempted.
077   * @param tableName the name of the table
078   */
079  AsyncTableBuilder<AdvancedScanResultConsumer> getTableBuilder(TableName tableName);
080
081  /**
082   * Retrieve an {@link AsyncTable} implementation for accessing a table.
083   * <p>
084   * This method no longer checks table existence. An exception will be thrown if the table does not
085   * exist only when the first operation is attempted.
086   * @param tableName the name of the table
087   * @param pool the thread pool to use for executing callback
088   * @return an AsyncTable to use for interactions with this table
089   */
090  default AsyncTable<ScanResultConsumer> getTable(TableName tableName, ExecutorService pool) {
091    return getTableBuilder(tableName, pool).build();
092  }
093
094  /**
095   * Returns an {@link AsyncTableBuilder} for creating {@link AsyncTable}.
096   * <p>
097   * This method no longer checks table existence. An exception will be thrown if the table does not
098   * exist only when the first operation is attempted.
099   * @param tableName the name of the table
100   * @param pool the thread pool to use for executing callback
101   */
102  AsyncTableBuilder<ScanResultConsumer> getTableBuilder(TableName tableName, ExecutorService pool);
103
104  /**
105   * Retrieve an {@link AsyncAdmin} implementation to administer an HBase cluster.
106   * <p>
107   * The returned instance will use default configs. Use {@link #getAdminBuilder()} if you want to
108   * customize some configs.
109   * <p>
110   * The admin operation's returned {@code CompletableFuture} will be finished directly in the rpc
111   * framework's callback thread, so typically you should not do any time consuming work inside
112   * these methods.
113   * @return an {@link AsyncAdmin} instance for cluster administration
114   */
115  default AsyncAdmin getAdmin() {
116    return getAdminBuilder().build();
117  }
118
119  /**
120   * Returns an {@link AsyncAdminBuilder} for creating {@link AsyncAdmin}.
121   * <p>
122   * The admin operation's returned {@code CompletableFuture} will be finished directly in the rpc
123   * framework's callback thread, so typically you should not do any time consuming work inside
124   * these methods.
125   */
126  AsyncAdminBuilder getAdminBuilder();
127
128  /**
129   * Retrieve an {@link AsyncAdmin} implementation to administer an HBase cluster.
130   * <p>
131   * The returned instance will use default configs. Use {@link #getAdminBuilder(ExecutorService)}
132   * if you want to customize some configs.
133   * @param pool the thread pool to use for executing callback
134   * @return an {@link AsyncAdmin} instance for cluster administration
135   */
136  default AsyncAdmin getAdmin(ExecutorService pool) {
137    return getAdminBuilder(pool).build();
138  }
139
140  /**
141   * Returns an {@link AsyncAdminBuilder} for creating {@link AsyncAdmin}.
142   * @param pool the thread pool to use for executing callback
143   */
144  AsyncAdminBuilder getAdminBuilder(ExecutorService pool);
145
146  /**
147   * Retrieve an {@link AsyncBufferedMutator} for performing client-side buffering of writes.
148   * <p>
149   * The returned instance will use default configs. Use
150   * {@link #getBufferedMutatorBuilder(TableName)} if you want to customize some configs.
151   * @param tableName the name of the table
152   * @return an {@link AsyncBufferedMutator} for the supplied tableName.
153   */
154  default AsyncBufferedMutator getBufferedMutator(TableName tableName) {
155    return getBufferedMutatorBuilder(tableName).build();
156  }
157
158  /**
159   * Returns an {@link AsyncBufferedMutatorBuilder} for creating {@link AsyncBufferedMutator}.
160   * @param tableName the name of the table
161   */
162  AsyncBufferedMutatorBuilder getBufferedMutatorBuilder(TableName tableName);
163
164  /**
165   * Retrieve an {@link AsyncBufferedMutator} for performing client-side buffering of writes.
166   * <p>
167   * The returned instance will use default configs. Use
168   * {@link #getBufferedMutatorBuilder(TableName, ExecutorService)} if you want to customize some
169   * configs.
170   * @param tableName the name of the table
171   * @param pool the thread pool to use for executing callback
172   * @return an {@link AsyncBufferedMutator} for the supplied tableName.
173   */
174  default AsyncBufferedMutator getBufferedMutator(TableName tableName, ExecutorService pool) {
175    return getBufferedMutatorBuilder(tableName, pool).build();
176  }
177
178  /**
179   * Returns an {@link AsyncBufferedMutatorBuilder} for creating {@link AsyncBufferedMutator}.
180   * @param tableName the name of the table
181   * @param pool the thread pool to use for executing callback
182   */
183  AsyncBufferedMutatorBuilder getBufferedMutatorBuilder(TableName tableName, ExecutorService pool);
184}