2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.client
;
20 import static org
.apache
.hadoop
.hbase
.client
.ConnectionUtils
.retries2Attempts
;
22 import java
.util
.concurrent
.TimeUnit
;
24 import org
.apache
.hadoop
.hbase
.TableName
;
25 import org
.apache
.yetus
.audience
.InterfaceAudience
;
28 * Base class for all asynchronous table builders.
30 @InterfaceAudience.Private
31 abstract class AsyncTableBuilderBase
<C
extends ScanResultConsumerBase
>
32 implements AsyncTableBuilder
<C
> {
34 protected TableName tableName
;
36 protected long operationTimeoutNs
;
38 protected long scanTimeoutNs
;
40 protected long rpcTimeoutNs
;
42 protected long readRpcTimeoutNs
;
44 protected long writeRpcTimeoutNs
;
46 protected long pauseNs
;
48 protected long pauseForCQTBENs
;
50 protected int maxAttempts
;
52 protected int startLogErrorsCnt
;
54 AsyncTableBuilderBase(TableName tableName
, AsyncConnectionConfiguration connConf
) {
55 this.tableName
= tableName
;
56 this.operationTimeoutNs
= tableName
.isSystemTable() ? connConf
.getMetaOperationTimeoutNs()
57 : connConf
.getOperationTimeoutNs();
58 this.scanTimeoutNs
= connConf
.getScanTimeoutNs();
59 this.rpcTimeoutNs
= connConf
.getRpcTimeoutNs();
60 this.readRpcTimeoutNs
= connConf
.getReadRpcTimeoutNs();
61 this.writeRpcTimeoutNs
= connConf
.getWriteRpcTimeoutNs();
62 this.pauseNs
= connConf
.getPauseNs();
63 this.pauseForCQTBENs
= connConf
.getPauseForCQTBENs();
64 this.maxAttempts
= retries2Attempts(connConf
.getMaxRetries());
65 this.startLogErrorsCnt
= connConf
.getStartLogErrorsCnt();
69 public AsyncTableBuilderBase
<C
> setOperationTimeout(long timeout
, TimeUnit unit
) {
70 this.operationTimeoutNs
= unit
.toNanos(timeout
);
75 public AsyncTableBuilderBase
<C
> setScanTimeout(long timeout
, TimeUnit unit
) {
76 this.scanTimeoutNs
= unit
.toNanos(timeout
);
81 public AsyncTableBuilderBase
<C
> setRpcTimeout(long timeout
, TimeUnit unit
) {
82 this.rpcTimeoutNs
= unit
.toNanos(timeout
);
87 public AsyncTableBuilderBase
<C
> setReadRpcTimeout(long timeout
, TimeUnit unit
) {
88 this.readRpcTimeoutNs
= unit
.toNanos(timeout
);
93 public AsyncTableBuilderBase
<C
> setWriteRpcTimeout(long timeout
, TimeUnit unit
) {
94 this.writeRpcTimeoutNs
= unit
.toNanos(timeout
);
99 public AsyncTableBuilderBase
<C
> setRetryPause(long pause
, TimeUnit unit
) {
100 this.pauseNs
= unit
.toNanos(pause
);
105 public AsyncTableBuilderBase
<C
> setRetryPauseForCQTBE(long pause
, TimeUnit unit
) {
106 this.pauseForCQTBENs
= unit
.toNanos(pause
);
111 public AsyncTableBuilderBase
<C
> setMaxAttempts(int maxAttempts
) {
112 this.maxAttempts
= maxAttempts
;
117 public AsyncTableBuilderBase
<C
> setStartLogErrorsCnt(int startLogErrorsCnt
) {
118 this.startLogErrorsCnt
= startLogErrorsCnt
;