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
039  TableBuilderBase(TableName tableName, ConnectionConfiguration connConf) {
040    if (tableName == null) {
041      throw new IllegalArgumentException("Given table name is null");
042    }
043    this.tableName = tableName;
044    this.operationTimeout = tableName.isSystemTable()
045      ? connConf.getMetaOperationTimeout()
046      : connConf.getOperationTimeout();
047    this.rpcTimeout = connConf.getRpcTimeout();
048    this.readRpcTimeout =
049      tableName.isSystemTable() ? connConf.getMetaReadRpcTimeout() : connConf.getReadRpcTimeout();
050    this.writeRpcTimeout = connConf.getWriteRpcTimeout();
051  }
052
053  @Override
054  public TableBuilderBase setOperationTimeout(int timeout) {
055    this.operationTimeout = timeout;
056    return this;
057  }
058
059  @Override
060  public TableBuilderBase setRpcTimeout(int timeout) {
061    this.rpcTimeout = timeout;
062    return this;
063  }
064
065  @Override
066  public TableBuilderBase setReadRpcTimeout(int timeout) {
067    this.readRpcTimeout = timeout;
068    return this;
069  }
070
071  @Override
072  public TableBuilderBase setWriteRpcTimeout(int timeout) {
073    this.writeRpcTimeout = timeout;
074    return this;
075  }
076}