View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.hadoop.hbase.thrift;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.hadoop.classification.InterfaceAudience;
25  import org.apache.hadoop.conf.Configuration;
26  import org.apache.thrift.server.TThreadedSelectorServer;
27  import org.apache.thrift.transport.TNonblockingServerTransport;
28  
29  /**
30   * A TThreadedSelectorServer.Args that reads hadoop configuration
31   */
32  @InterfaceAudience.Private
33  public class HThreadedSelectorServerArgs extends TThreadedSelectorServer.Args {
34    private static final Log LOG = LogFactory.getLog(TThreadedSelectorServer.class);
35  
36    /**
37     * Number of selector threads for reading and writing socket
38     */
39    public static final String SELECTOR_THREADS_CONF_KEY =
40        "hbase.thrift.selector.threads";
41  
42    /**
43     * Number fo threads for processing the thrift calls
44     */
45    public static final String WORKER_THREADS_CONF_KEY =
46        "hbase.thrift.worker.threads";
47  
48    /**
49     * Time to wait for server to stop gracefully
50     */
51    public static final String STOP_TIMEOUT_CONF_KEY =
52        "hbase.thrift.stop.timeout.seconds";
53  
54    /**
55     * Maximum number of accepted elements per selector
56     */
57    public static final String ACCEPT_QUEUE_SIZE_PER_THREAD_CONF_KEY =
58        "hbase.thrift.accept.queue.size.per.selector";
59  
60    /**
61     * The strategy for handling new accepted connections.
62     */
63    public static final String ACCEPT_POLICY_CONF_KEY =
64        "hbase.thrift.accept.policy";
65  
66    public HThreadedSelectorServerArgs(
67        TNonblockingServerTransport transport, Configuration conf) {
68      super(transport);
69      readConf(conf);
70    }
71  
72    private void readConf(Configuration conf) {
73      int selectorThreads = conf.getInt(
74          SELECTOR_THREADS_CONF_KEY, getSelectorThreads());
75      int workerThreads = conf.getInt(
76          WORKER_THREADS_CONF_KEY, getWorkerThreads());
77      int stopTimeoutVal = conf.getInt(
78          STOP_TIMEOUT_CONF_KEY, getStopTimeoutVal());
79      int acceptQueueSizePerThread = conf.getInt(
80          ACCEPT_QUEUE_SIZE_PER_THREAD_CONF_KEY, getAcceptQueueSizePerThread());
81      AcceptPolicy acceptPolicy = AcceptPolicy.valueOf(conf.get(
82          ACCEPT_POLICY_CONF_KEY, getAcceptPolicy().toString()).toUpperCase());
83  
84      super.selectorThreads(selectorThreads)
85           .workerThreads(workerThreads)
86           .stopTimeoutVal(stopTimeoutVal)
87           .acceptQueueSizePerThread(acceptQueueSizePerThread)
88           .acceptPolicy(acceptPolicy);
89  
90      LOG.info("Read configuration selectorThreads:" + selectorThreads +
91               " workerThreads:" + workerThreads +
92               " stopTimeoutVal:" + stopTimeoutVal + "sec" +
93               " acceptQueueSizePerThread:" + acceptQueueSizePerThread +
94               " acceptPolicy:" + acceptPolicy);
95    }
96  }