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