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 java.util.Locale;
23  import org.apache.commons.logging.Log;
24  import org.apache.commons.logging.LogFactory;
25  import org.apache.hadoop.hbase.classification.InterfaceAudience;
26  import org.apache.hadoop.conf.Configuration;
27  import org.apache.thrift.server.TThreadedSelectorServer;
28  import org.apache.thrift.transport.TNonblockingServerTransport;
29
30  /**
31   * A TThreadedSelectorServer.Args that reads hadoop configuration
32   */
33  @InterfaceAudience.Private
34  public class HThreadedSelectorServerArgs extends TThreadedSelectorServer.Args {
35    private static final Log LOG = LogFactory.getLog(TThreadedSelectorServer.class);
36
37    /**
38     * Number of selector threads for reading and writing socket
39     */
40    public static final String SELECTOR_THREADS_CONF_KEY =
41        "hbase.thrift.selector.threads";
42
43    /**
44     * Number fo threads for processing the thrift calls
45     */
46    public static final String WORKER_THREADS_CONF_KEY =
47        "hbase.thrift.worker.threads";
48
49    /**
50     * Time to wait for server to stop gracefully
51     */
52    public static final String STOP_TIMEOUT_CONF_KEY =
53        "hbase.thrift.stop.timeout.seconds";
54
55    /**
56     * Maximum number of accepted elements per selector
57     */
58    public static final String ACCEPT_QUEUE_SIZE_PER_THREAD_CONF_KEY =
59        "hbase.thrift.accept.queue.size.per.selector";
60
61    /**
62     * The strategy for handling new accepted connections.
63     */
64    public static final String ACCEPT_POLICY_CONF_KEY =
65        "hbase.thrift.accept.policy";
66
67    public HThreadedSelectorServerArgs(
68        TNonblockingServerTransport transport, Configuration conf) {
69      super(transport);
70      readConf(conf);
71    }
72
73    private void readConf(Configuration conf) {
74      int selectorThreads = conf.getInt(
75          SELECTOR_THREADS_CONF_KEY, getSelectorThreads());
76      int workerThreads = conf.getInt(
77          WORKER_THREADS_CONF_KEY, getWorkerThreads());
78      int stopTimeoutVal = conf.getInt(
79          STOP_TIMEOUT_CONF_KEY, getStopTimeoutVal());
80      int acceptQueueSizePerThread = conf.getInt(
81          ACCEPT_QUEUE_SIZE_PER_THREAD_CONF_KEY, getAcceptQueueSizePerThread());
82      AcceptPolicy acceptPolicy = AcceptPolicy.valueOf(conf.get(
83          ACCEPT_POLICY_CONF_KEY, getAcceptPolicy().toString()).toUpperCase(Locale.ROOT));
84
85      super.selectorThreads(selectorThreads)
86           .workerThreads(workerThreads)
87           .stopTimeoutVal(stopTimeoutVal)
88           .acceptQueueSizePerThread(acceptQueueSizePerThread)
89           .acceptPolicy(acceptPolicy);
90
91      LOG.info("Read configuration selectorThreads:" + selectorThreads +
92               " workerThreads:" + workerThreads +
93               " stopTimeoutVal:" + stopTimeoutVal + "sec" +
94               " acceptQueueSizePerThread:" + acceptQueueSizePerThread +
95               " acceptPolicy:" + acceptPolicy);
96    }
97  }