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,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020package org.apache.hadoop.hbase.thrift;
021
022import java.util.Locale;
023
024import org.apache.hadoop.conf.Configuration;
025import org.apache.thrift.server.TThreadedSelectorServer;
026import org.apache.thrift.transport.TNonblockingServerTransport;
027import org.apache.yetus.audience.InterfaceAudience;
028import org.slf4j.Logger;
029import org.slf4j.LoggerFactory;
030
031/**
032 * A TThreadedSelectorServer.Args that reads hadoop configuration
033 */
034@InterfaceAudience.Private
035public class HThreadedSelectorServerArgs extends TThreadedSelectorServer.Args {
036  private static final Logger LOG = LoggerFactory.getLogger(TThreadedSelectorServer.class);
037
038  /**
039   * Number of selector threads for reading and writing socket
040   */
041  public static final String SELECTOR_THREADS_CONF_KEY =
042      "hbase.thrift.selector.threads";
043
044  /**
045   * Number fo threads for processing the thrift calls
046   */
047  public static final String WORKER_THREADS_CONF_KEY =
048      "hbase.thrift.worker.threads";
049
050  /**
051   * Time to wait for server to stop gracefully
052   */
053  public static final String STOP_TIMEOUT_CONF_KEY =
054      "hbase.thrift.stop.timeout.seconds";
055
056  /**
057   * Maximum number of accepted elements per selector
058   */
059  public static final String ACCEPT_QUEUE_SIZE_PER_THREAD_CONF_KEY =
060      "hbase.thrift.accept.queue.size.per.selector";
061
062  /**
063   * The strategy for handling new accepted connections.
064   */
065  public static final String ACCEPT_POLICY_CONF_KEY =
066      "hbase.thrift.accept.policy";
067
068  public HThreadedSelectorServerArgs(
069      TNonblockingServerTransport transport, Configuration conf) {
070    super(transport);
071    readConf(conf);
072  }
073
074  private void readConf(Configuration conf) {
075    int selectorThreads = conf.getInt(
076        SELECTOR_THREADS_CONF_KEY, getSelectorThreads());
077    int workerThreads = conf.getInt(
078        WORKER_THREADS_CONF_KEY, getWorkerThreads());
079    int stopTimeoutVal = conf.getInt(
080        STOP_TIMEOUT_CONF_KEY, getStopTimeoutVal());
081    int acceptQueueSizePerThread = conf.getInt(
082        ACCEPT_QUEUE_SIZE_PER_THREAD_CONF_KEY, getAcceptQueueSizePerThread());
083    AcceptPolicy acceptPolicy = AcceptPolicy.valueOf(conf.get(
084        ACCEPT_POLICY_CONF_KEY, getAcceptPolicy().toString()).toUpperCase(Locale.ROOT));
085
086    super.selectorThreads(selectorThreads)
087         .workerThreads(workerThreads)
088         .stopTimeoutVal(stopTimeoutVal)
089         .acceptQueueSizePerThread(acceptQueueSizePerThread)
090         .acceptPolicy(acceptPolicy);
091
092    LOG.info("Read configuration selectorThreads:" + selectorThreads +
093             " workerThreads:" + workerThreads +
094             " stopTimeoutVal:" + stopTimeoutVal + "sec" +
095             " acceptQueueSizePerThread:" + acceptQueueSizePerThread +
096             " acceptPolicy:" + acceptPolicy);
097  }
098}