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;
023import org.apache.hadoop.hbase.HBaseServerException;
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 #setRetryPauseForServerOverloaded(long, TimeUnit)
054   */
055  AsyncAdminBuilder setRetryPause(long timeout, TimeUnit unit);
056
057  /**
058   * Set the base pause time for retrying when {@link HBaseServerException#isServerOverloaded()}. We
059   * use an exponential policy to generate sleep time from this base 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
063   * {@link HBaseServerException#isServerOverloaded()} means the server is overloaded. We just use
064   * the normal pause value for {@link HBaseServerException#isServerOverloaded()} if here you
065   * specify a smaller value.
066   * @see #setRetryPause(long, TimeUnit)
067   * @deprecated Since 2.5.0, will be removed in 4.0.0. Please use
068   *             {@link #setRetryPauseForServerOverloaded(long, TimeUnit)} instead.
069   */
070  @Deprecated
071  default AsyncAdminBuilder setRetryPauseForCQTBE(long pause, TimeUnit unit) {
072    return setRetryPauseForServerOverloaded(pause, unit);
073  }
074
075  /**
076   * Set the base pause time for retrying when {@link HBaseServerException#isServerOverloaded()}. We
077   * use an exponential policy to generate sleep time when retrying.
078   * <p/>
079   * This value should be greater than the normal pause value which could be set with the above
080   * {@link #setRetryPause(long, TimeUnit)} method, as usually
081   * {@link HBaseServerException#isServerOverloaded()} means the server is overloaded. We just use
082   * the normal pause value for {@link HBaseServerException#isServerOverloaded()} if here you
083   * specify a smaller value.
084   * @see #setRetryPause(long, TimeUnit)
085   */
086  AsyncAdminBuilder setRetryPauseForServerOverloaded(long pause, TimeUnit unit);
087
088  /**
089   * Set the max retry times for an admin operation. Usually it is the max attempt times minus 1.
090   * Operation timeout and max attempt times(or max retry times) are both limitations for retrying,
091   * we will stop retrying when we reach any of the limitations.
092   * @return this for invocation chaining
093   */
094  default AsyncAdminBuilder setMaxRetries(int maxRetries) {
095    return setMaxAttempts(retries2Attempts(maxRetries));
096  }
097
098  /**
099   * Set the max attempt times for an admin operation. Usually it is the max retry times plus 1.
100   * Operation timeout and max attempt times(or max retry times) are both limitations for retrying,
101   * we will stop retrying when we reach any of the limitations.
102   * @return this for invocation chaining
103   */
104  AsyncAdminBuilder setMaxAttempts(int maxAttempts);
105
106  /**
107   * Set the number of retries that are allowed before we start to log.
108   * @return this for invocation chaining
109   */
110  AsyncAdminBuilder setStartLogErrorsCnt(int startLogErrorsCnt);
111
112  /**
113   * Create a {@link AsyncAdmin} instance.
114   * @return a {@link AsyncAdmin} instance
115   */
116  AsyncAdmin build();
117}