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