1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.hbql.client;
22
23 import org.apache.hadoop.hbase.hbql.impl.QueryExecutorPoolImpl;
24 import org.apache.hadoop.hbase.hbql.impl.Utils;
25 import org.apache.hadoop.hbase.hbql.util.Maps;
26
27 import java.util.Map;
28 import java.util.Set;
29
30 public class QueryExecutorPoolManager {
31
32 public static int defaultMaxExecutorPoolSize = 5;
33 public static int defaultMinThreadCount = 1;
34 public static int defaultMaxThreadCount = 10;
35 public static long defaultKeepAliveSecs = Long.MAX_VALUE;
36 public static boolean defaultThreadsReadResults = true;
37 public static int defaultCompletionQueueSize = 25;
38
39 private static Map<String, QueryExecutorPoolImpl> executorPoolMap = Maps.newConcurrentHashMap();
40
41 private static Map<String, QueryExecutorPoolImpl> getExecutorPoolMap() {
42 return QueryExecutorPoolManager.executorPoolMap;
43 }
44
45 public static QueryExecutorPool newQueryExecutorPool(final String poolName,
46 final int maxExecutorPoolSize,
47 final int minThreadCount,
48 final int maxThreadCount,
49 final long keepAliveSecs,
50 final boolean threadsReadResults,
51 final int completionQueueSize) throws HBqlException {
52
53 if (Utils.isValidString(poolName) && getExecutorPoolMap().containsKey(poolName))
54 throw new HBqlException("QueryExecutorPool already exists: " + poolName);
55
56 final QueryExecutorPoolImpl executorPool = new QueryExecutorPoolImpl(poolName,
57 maxExecutorPoolSize,
58 minThreadCount,
59 maxThreadCount,
60 keepAliveSecs,
61 threadsReadResults,
62 completionQueueSize);
63 QueryExecutorPoolManager.getExecutorPoolMap().put(executorPool.getName(), executorPool);
64
65 return executorPool;
66 }
67
68 public static boolean dropQueryExecutorPool(final String name) {
69
70 if (Utils.isValidString(name) && getExecutorPoolMap().containsKey(name)) {
71 final QueryExecutorPoolImpl queryExecutorPool = getExecutorPoolMap().remove(name);
72 queryExecutorPool.shutdown();
73 return true;
74 }
75
76 return false;
77 }
78
79 public static boolean queryExecutorPoolExists(final String name) {
80 return Utils.isValidString(name) && QueryExecutorPoolManager.getExecutorPoolMap().containsKey(name);
81 }
82
83 public static QueryExecutorPool getQueryExecutorPool(final String poolName) throws HBqlException {
84 if (!QueryExecutorPoolManager.getExecutorPoolMap().containsKey(poolName))
85 throw new HBqlException("QueryExecutorPool does not exist: " + poolName);
86
87 return QueryExecutorPoolManager.getExecutorPoolMap().get(poolName);
88 }
89
90 public static Set<String> getQueryExecutorPoolNames() {
91 return QueryExecutorPoolManager.getExecutorPoolMap().keySet();
92 }
93 }