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 static org.apache.hadoop.hbase.client.ConnectionUtils.retries2Attempts;
021
022import java.util.concurrent.TimeUnit;
023
024import org.apache.yetus.audience.InterfaceAudience;
025
026/**
027 * For creating {@link AsyncAdmin}. The implementation should have default configurations set before
028 * returning the builder to user. So users are free to only set the configs they care about to
029 * create a new AsyncAdmin instance.
030 * @since 2.0.0
031 */
032@InterfaceAudience.Public
033public interface AsyncAdminBuilder {
034
035  /**
036   * Set timeout for a whole admin operation. Operation timeout and max attempt times(or max retry
037   * times) are both limitations for retrying, we will stop retrying when we reach any of the
038   * limitations.
039   * @return this for invocation chaining
040   */
041  AsyncAdminBuilder setOperationTimeout(long timeout, TimeUnit unit);
042
043  /**
044   * Set timeout for each rpc request.
045   * @return this for invocation chaining
046   */
047  AsyncAdminBuilder setRpcTimeout(long timeout, TimeUnit unit);
048
049  /**
050   * Set the base pause time for retrying. We use an exponential policy to generate sleep time when
051   * retrying.
052   * @return this for invocation chaining
053   * @see #setRetryPauseForCQTBE(long, TimeUnit)
054   */
055  AsyncAdminBuilder setRetryPause(long timeout, TimeUnit unit);
056
057  /**
058   * Set the base pause time for retrying when we hit {@code CallQueueTooBigException}. We use an
059   * exponential policy to generate sleep time when retrying.
060   * <p/>
061   * This value should be greater than the normal pause value which could be set with the above
062   * {@link #setRetryPause(long, TimeUnit)} method, as usually {@code CallQueueTooBigException}
063   * means the server is overloaded. We just use the normal pause value for
064   * {@code CallQueueTooBigException} if here you specify a smaller value.
065   * @see #setRetryPause(long, TimeUnit)
066   */
067  AsyncAdminBuilder setRetryPauseForCQTBE(long pause, TimeUnit unit);
068
069  /**
070   * Set the max retry times for an admin operation. Usually it is the max attempt times minus 1.
071   * Operation timeout and max attempt times(or max retry times) are both limitations for retrying,
072   * we will stop retrying when we reach any of the limitations.
073   * @return this for invocation chaining
074   */
075  default AsyncAdminBuilder setMaxRetries(int maxRetries) {
076    return setMaxAttempts(retries2Attempts(maxRetries));
077  }
078
079  /**
080   * Set the max attempt times for an admin operation. Usually it is the max retry times plus 1.
081   * Operation timeout and max attempt times(or max retry times) are both limitations for retrying,
082   * we will stop retrying when we reach any of the limitations.
083   * @return this for invocation chaining
084   */
085  AsyncAdminBuilder setMaxAttempts(int maxAttempts);
086
087  /**
088   * Set the number of retries that are allowed before we start to log.
089   * @return this for invocation chaining
090   */
091  AsyncAdminBuilder setStartLogErrorsCnt(int startLogErrorsCnt);
092
093  /**
094   * Create a {@link AsyncAdmin} instance.
095   * @return a {@link AsyncAdmin} instance
096   */
097  AsyncAdmin build();
098}