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