View Javadoc

1   /*
2    * Copyright (c) 2010.  The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  
21  package org.apache.hadoop.hbase.hbql.impl;
22  
23  import org.apache.hadoop.hbase.hbql.client.HBqlException;
24  import org.apache.hadoop.hbase.hbql.client.QueryExecutorPool;
25  
26  public class QueryExecutorPoolImpl extends ElementPool<CompletionQueueExecutor> implements QueryExecutorPool {
27  
28      private final int minThreadCount;
29      private final int maxThreadCount;
30      private final long keepAliveSecs;
31      private final boolean threadsReadResults;
32      private final int completionQueueSize;
33  
34      public QueryExecutorPoolImpl(final String poolName,
35                                   final int maxExecutorPoolSize,
36                                   final int minThreadCount,
37                                   final int maxThreadCount,
38                                   final long keepAliveSecs,
39                                   final boolean threadsReadResults,
40                                   final int completionQueueSize) {
41          super(poolName, maxExecutorPoolSize);
42          this.minThreadCount = minThreadCount;
43          this.maxThreadCount = maxThreadCount;
44          this.keepAliveSecs = keepAliveSecs;
45          this.threadsReadResults = threadsReadResults;
46          this.completionQueueSize = completionQueueSize;
47      }
48  
49      public int getMinThreadCount() {
50          return this.minThreadCount;
51      }
52  
53      public int getMaxThreadCount() {
54          return this.maxThreadCount;
55      }
56  
57      public long getKeepAliveSecs() {
58          return this.keepAliveSecs;
59      }
60  
61      public boolean getThreadsReadResults() {
62          return this.threadsReadResults;
63      }
64  
65      public int getCompletionQueueSize() {
66          return this.completionQueueSize;
67      }
68  
69      protected CompletionQueueExecutor newElement() throws HBqlException {
70          return this.getThreadsReadResults()
71                 ? ResultExecutor.newPooledResultExecutor(this,
72                                                          this.getMinThreadCount(),
73                                                          this.getMaxThreadCount(),
74                                                          this.getKeepAliveSecs(),
75                                                          this.getCompletionQueueSize())
76                 : ResultScannerExecutor.newPooledResultScannerExecutor(this,
77                                                                        this.getMinThreadCount(),
78                                                                        this.getMaxThreadCount(),
79                                                                        this.getKeepAliveSecs(),
80                                                                        this.getCompletionQueueSize());
81      }
82  
83      public void shutdown() {
84          for (final CompletionQueueExecutor val : this.getElementPool()) {
85              val.shutdown();
86          }
87      }
88  }