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 int maxAttempts; 049 050 protected int startLogErrorsCnt; 051 052 AsyncTableBuilderBase(TableName tableName, AsyncConnectionConfiguration connConf) { 053 this.tableName = tableName; 054 this.operationTimeoutNs = tableName.isSystemTable() ? connConf.getMetaOperationTimeoutNs() 055 : connConf.getOperationTimeoutNs(); 056 this.scanTimeoutNs = connConf.getScanTimeoutNs(); 057 this.rpcTimeoutNs = connConf.getRpcTimeoutNs(); 058 this.readRpcTimeoutNs = connConf.getReadRpcTimeoutNs(); 059 this.writeRpcTimeoutNs = connConf.getWriteRpcTimeoutNs(); 060 this.pauseNs = connConf.getPauseNs(); 061 this.maxAttempts = retries2Attempts(connConf.getMaxRetries()); 062 this.startLogErrorsCnt = connConf.getStartLogErrorsCnt(); 063 } 064 065 @Override 066 public AsyncTableBuilderBase<C> setOperationTimeout(long timeout, TimeUnit unit) { 067 this.operationTimeoutNs = unit.toNanos(timeout); 068 return this; 069 } 070 071 @Override 072 public AsyncTableBuilderBase<C> setScanTimeout(long timeout, TimeUnit unit) { 073 this.scanTimeoutNs = unit.toNanos(timeout); 074 return this; 075 } 076 077 @Override 078 public AsyncTableBuilderBase<C> setRpcTimeout(long timeout, TimeUnit unit) { 079 this.rpcTimeoutNs = unit.toNanos(timeout); 080 return this; 081 } 082 083 @Override 084 public AsyncTableBuilderBase<C> setReadRpcTimeout(long timeout, TimeUnit unit) { 085 this.readRpcTimeoutNs = unit.toNanos(timeout); 086 return this; 087 } 088 089 @Override 090 public AsyncTableBuilderBase<C> setWriteRpcTimeout(long timeout, TimeUnit unit) { 091 this.writeRpcTimeoutNs = unit.toNanos(timeout); 092 return this; 093 } 094 095 @Override 096 public AsyncTableBuilderBase<C> setRetryPause(long pause, TimeUnit unit) { 097 this.pauseNs = unit.toNanos(pause); 098 return this; 099 } 100 101 @Override 102 public AsyncTableBuilderBase<C> setMaxAttempts(int maxAttempts) { 103 this.maxAttempts = maxAttempts; 104 return this; 105 } 106 107 @Override 108 public AsyncTableBuilderBase<C> setStartLogErrorsCnt(int startLogErrorsCnt) { 109 this.startLogErrorsCnt = startLogErrorsCnt; 110 return this; 111 } 112}