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.thrift; 019 020import java.util.Locale; 021import org.apache.hadoop.conf.Configuration; 022import org.apache.yetus.audience.InterfaceAudience; 023import org.slf4j.Logger; 024import org.slf4j.LoggerFactory; 025 026import org.apache.hbase.thirdparty.org.apache.thrift.server.TThreadedSelectorServer; 027import org.apache.hbase.thirdparty.org.apache.thrift.transport.TNonblockingServerTransport; 028 029/** 030 * A TThreadedSelectorServer.Args that reads hadoop configuration 031 */ 032@InterfaceAudience.Private 033public class HThreadedSelectorServerArgs extends TThreadedSelectorServer.Args { 034 private static final Logger LOG = LoggerFactory.getLogger(HThreadedSelectorServerArgs.class); 035 036 /** 037 * Number of selector threads for reading and writing socket 038 */ 039 public static final String SELECTOR_THREADS_CONF_KEY = "hbase.thrift.selector.threads"; 040 041 /** 042 * Number fo threads for processing the thrift calls 043 */ 044 public static final String WORKER_THREADS_CONF_KEY = "hbase.thrift.worker.threads"; 045 046 /** 047 * Time to wait for server to stop gracefully 048 */ 049 public static final String STOP_TIMEOUT_CONF_KEY = "hbase.thrift.stop.timeout.seconds"; 050 051 /** 052 * Maximum number of accepted elements per selector 053 */ 054 public static final String ACCEPT_QUEUE_SIZE_PER_THREAD_CONF_KEY = 055 "hbase.thrift.accept.queue.size.per.selector"; 056 057 /** 058 * The strategy for handling new accepted connections. 059 */ 060 public static final String ACCEPT_POLICY_CONF_KEY = "hbase.thrift.accept.policy"; 061 062 public HThreadedSelectorServerArgs(TNonblockingServerTransport transport, Configuration conf) { 063 super(transport); 064 readConf(conf); 065 } 066 067 private void readConf(Configuration conf) { 068 int selectorThreads = conf.getInt(SELECTOR_THREADS_CONF_KEY, getSelectorThreads()); 069 int workerThreads = conf.getInt(WORKER_THREADS_CONF_KEY, getWorkerThreads()); 070 int stopTimeoutVal = conf.getInt(STOP_TIMEOUT_CONF_KEY, getStopTimeoutVal()); 071 int acceptQueueSizePerThread = 072 conf.getInt(ACCEPT_QUEUE_SIZE_PER_THREAD_CONF_KEY, getAcceptQueueSizePerThread()); 073 AcceptPolicy acceptPolicy = AcceptPolicy.valueOf( 074 conf.get(ACCEPT_POLICY_CONF_KEY, getAcceptPolicy().toString()).toUpperCase(Locale.ROOT)); 075 076 super.selectorThreads(selectorThreads).workerThreads(workerThreads) 077 .stopTimeoutVal(stopTimeoutVal).acceptQueueSizePerThread(acceptQueueSizePerThread) 078 .acceptPolicy(acceptPolicy); 079 080 LOG.info("Read configuration selectorThreads:" + selectorThreads + " workerThreads:" 081 + workerThreads + " stopTimeoutVal:" + stopTimeoutVal + "sec" + " acceptQueueSizePerThread:" 082 + acceptQueueSizePerThread + " acceptPolicy:" + acceptPolicy); 083 } 084}