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.hadoop.hbase.TableName; 025import org.apache.yetus.audience.InterfaceAudience; 026 027/** 028 * Base class for all asynchronous table builders. 029 */ 030@InterfaceAudience.Private 031abstract class AsyncTableBuilderBase<C extends ScanResultConsumerBase> 032 implements AsyncTableBuilder<C> { 033 034 protected TableName tableName; 035 036 protected long operationTimeoutNs; 037 038 protected long scanTimeoutNs; 039 040 protected long rpcTimeoutNs; 041 042 protected long readRpcTimeoutNs; 043 044 protected long writeRpcTimeoutNs; 045 046 protected long pauseNs; 047 048 protected long pauseForCQTBENs; 049 050 protected int maxAttempts; 051 052 protected int startLogErrorsCnt; 053 054 AsyncTableBuilderBase(TableName tableName, AsyncConnectionConfiguration connConf) { 055 this.tableName = tableName; 056 this.operationTimeoutNs = tableName.isSystemTable() ? connConf.getMetaOperationTimeoutNs() 057 : connConf.getOperationTimeoutNs(); 058 this.scanTimeoutNs = connConf.getScanTimeoutNs(); 059 this.rpcTimeoutNs = connConf.getRpcTimeoutNs(); 060 this.readRpcTimeoutNs = connConf.getReadRpcTimeoutNs(); 061 this.writeRpcTimeoutNs = connConf.getWriteRpcTimeoutNs(); 062 this.pauseNs = connConf.getPauseNs(); 063 this.pauseForCQTBENs = connConf.getPauseForCQTBENs(); 064 this.maxAttempts = retries2Attempts(connConf.getMaxRetries()); 065 this.startLogErrorsCnt = connConf.getStartLogErrorsCnt(); 066 } 067 068 @Override 069 public AsyncTableBuilderBase<C> setOperationTimeout(long timeout, TimeUnit unit) { 070 this.operationTimeoutNs = unit.toNanos(timeout); 071 return this; 072 } 073 074 @Override 075 public AsyncTableBuilderBase<C> setScanTimeout(long timeout, TimeUnit unit) { 076 this.scanTimeoutNs = unit.toNanos(timeout); 077 return this; 078 } 079 080 @Override 081 public AsyncTableBuilderBase<C> setRpcTimeout(long timeout, TimeUnit unit) { 082 this.rpcTimeoutNs = unit.toNanos(timeout); 083 return this; 084 } 085 086 @Override 087 public AsyncTableBuilderBase<C> setReadRpcTimeout(long timeout, TimeUnit unit) { 088 this.readRpcTimeoutNs = unit.toNanos(timeout); 089 return this; 090 } 091 092 @Override 093 public AsyncTableBuilderBase<C> setWriteRpcTimeout(long timeout, TimeUnit unit) { 094 this.writeRpcTimeoutNs = unit.toNanos(timeout); 095 return this; 096 } 097 098 @Override 099 public AsyncTableBuilderBase<C> setRetryPause(long pause, TimeUnit unit) { 100 this.pauseNs = unit.toNanos(pause); 101 return this; 102 } 103 104 @Override 105 public AsyncTableBuilderBase<C> setRetryPauseForCQTBE(long pause, TimeUnit unit) { 106 this.pauseForCQTBENs = unit.toNanos(pause); 107 return this; 108 } 109 110 @Override 111 public AsyncTableBuilderBase<C> setMaxAttempts(int maxAttempts) { 112 this.maxAttempts = maxAttempts; 113 return this; 114 } 115 116 @Override 117 public AsyncTableBuilderBase<C> setStartLogErrorsCnt(int startLogErrorsCnt) { 118 this.startLogErrorsCnt = startLogErrorsCnt; 119 return this; 120 } 121}