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 java.util.Collections; 021import java.util.HashMap; 022import java.util.Map; 023import org.apache.hadoop.hbase.TableName; 024import org.apache.yetus.audience.InterfaceAudience; 025 026/** 027 * Base class for all table builders. 028 */ 029@InterfaceAudience.Private 030abstract class TableBuilderBase implements TableBuilder { 031 032 protected TableName tableName; 033 034 protected int operationTimeout; 035 036 protected int rpcTimeout; 037 038 protected int readRpcTimeout; 039 040 protected int writeRpcTimeout; 041 protected final int scanReadRpcTimeout; 042 protected int scanTimeout; 043 044 protected Map<String, byte[]> requestAttributes = Collections.emptyMap(); 045 046 TableBuilderBase(TableName tableName, ConnectionConfiguration connConf) { 047 if (tableName == null) { 048 throw new IllegalArgumentException("Given table name is null"); 049 } 050 this.tableName = tableName; 051 this.operationTimeout = tableName.isSystemTable() 052 ? connConf.getMetaOperationTimeout() 053 : connConf.getOperationTimeout(); 054 this.rpcTimeout = connConf.getRpcTimeout(); 055 this.readRpcTimeout = connConf.getReadRpcTimeout(); 056 this.scanReadRpcTimeout = 057 tableName.isSystemTable() ? connConf.getMetaReadRpcTimeout() : readRpcTimeout; 058 this.scanTimeout = 059 tableName.isSystemTable() ? connConf.getMetaScanTimeout() : connConf.getScanTimeout(); 060 this.writeRpcTimeout = connConf.getWriteRpcTimeout(); 061 } 062 063 @Override 064 public TableBuilderBase setOperationTimeout(int timeout) { 065 this.operationTimeout = timeout; 066 return this; 067 } 068 069 @Override 070 public TableBuilderBase setRpcTimeout(int timeout) { 071 this.rpcTimeout = timeout; 072 return this; 073 } 074 075 @Override 076 public TableBuilderBase setReadRpcTimeout(int timeout) { 077 this.readRpcTimeout = timeout; 078 return this; 079 } 080 081 @Override 082 public TableBuilderBase setWriteRpcTimeout(int timeout) { 083 this.writeRpcTimeout = timeout; 084 return this; 085 } 086 087 @Override 088 public TableBuilderBase setRequestAttribute(String key, byte[] value) { 089 if (this.requestAttributes.isEmpty()) { 090 this.requestAttributes = new HashMap<>(); 091 } 092 this.requestAttributes.put(key, value); 093 return this; 094 } 095}