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