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.executor;
22
23 import org.apache.hadoop.hbase.hbql.client.HBqlException;
24 import org.apache.hadoop.hbase.hbql.client.QueryExecutorPoolManager;
25
26 import java.util.List;
27
28 public class QueryExecutorPoolDefinition {
29
30 private final String poolName;
31 private final List<ExecutorProperty> executorPropertyList;
32
33 private ExecutorProperty maxExecutorPoolSize = null;
34 private ExecutorProperty minThreadCount = null;
35 private ExecutorProperty maxThreadCount = null;
36 private ExecutorProperty keepAliveSecs = null;
37 private ExecutorProperty threadsReadResults = null;
38 private ExecutorProperty completionQueueSize = null;
39
40 public QueryExecutorPoolDefinition(final String poolName, final List<ExecutorProperty> executorPropertyList) {
41 this.poolName = poolName;
42 this.executorPropertyList = executorPropertyList;
43 }
44
45 public String getPoolName() {
46 return this.poolName;
47 }
48
49 private List<ExecutorProperty> getExecutorPoolPropertyList() {
50 return this.executorPropertyList;
51 }
52
53 private ExecutorProperty validateProperty(final ExecutorProperty assignee,
54 final ExecutorProperty value) throws HBqlException {
55 if (assignee != null)
56 throw new HBqlException("Multiple " + value.getPropertyType().getDescription()
57 + " values for " + this.getPoolName() + " not allowed");
58 return value;
59 }
60
61 public void validateExecutorPoolPropertyList() throws HBqlException {
62
63 if (this.getExecutorPoolPropertyList() == null)
64 return;
65
66 for (final ExecutorProperty executorProperty : this.getExecutorPoolPropertyList()) {
67
68 executorProperty.validate();
69
70 switch (executorProperty.getEnumType()) {
71
72 case MAX_EXECUTOR_POOL_SIZE:
73 this.maxExecutorPoolSize = this.validateProperty(this.maxExecutorPoolSize, executorProperty);
74 break;
75
76 case MIN_THREAD_COUNT:
77 this.minThreadCount = this.validateProperty(this.minThreadCount, executorProperty);
78 break;
79
80 case MAX_THREAD_COUNT:
81 this.maxThreadCount = this.validateProperty(this.maxThreadCount, executorProperty);
82 break;
83
84 case KEEP_ALIVE_SECS:
85 this.keepAliveSecs = this.validateProperty(this.keepAliveSecs, executorProperty);
86 break;
87
88 case THREADS_READ_RESULTS:
89 this.threadsReadResults = this.validateProperty(this.threadsReadResults, executorProperty);
90 break;
91
92 case COMPLETION_QUEUE_SIZE:
93 this.completionQueueSize = this.validateProperty(this.completionQueueSize, executorProperty);
94 break;
95 }
96 }
97 }
98
99 public int getMaxExecutorPoolSize() throws HBqlException {
100 if (this.maxExecutorPoolSize != null)
101 return this.maxExecutorPoolSize.getIntegerValue();
102 else
103 return QueryExecutorPoolManager.defaultMaxExecutorPoolSize;
104 }
105
106 public int getMinThreadCount() throws HBqlException {
107 if (this.minThreadCount != null)
108 return this.minThreadCount.getIntegerValue();
109 else
110 return QueryExecutorPoolManager.defaultMinThreadCount;
111 }
112
113 public int getMaxThreadCount() throws HBqlException {
114 if (this.maxThreadCount != null)
115 return this.maxThreadCount.getIntegerValue();
116 else
117 return QueryExecutorPoolManager.defaultMaxThreadCount;
118 }
119
120 public long getKeepAliveSecs() throws HBqlException {
121 if (this.keepAliveSecs != null)
122 return this.keepAliveSecs.getIntegerValue();
123 else
124 return QueryExecutorPoolManager.defaultKeepAliveSecs;
125 }
126
127 public boolean getThreadsReadResults() throws HBqlException {
128 if (this.threadsReadResults != null)
129 return this.threadsReadResults.getBooleanValue();
130 else
131 return QueryExecutorPoolManager.defaultThreadsReadResults;
132 }
133
134 public int getCompletionQueueSize() throws HBqlException {
135 if (this.completionQueueSize != null)
136 return this.completionQueueSize.getIntegerValue();
137 else
138 return QueryExecutorPoolManager.defaultCompletionQueueSize;
139 }
140
141 public String asString() {
142 try {
143 return " MAX_EXECUTOR_POOL_SIZE : " + this.getMaxExecutorPoolSize()
144 + ", MIN_THREAD_COUNT : " + this.getMinThreadCount()
145 + ", MAX_THREAD_COUNT : " + this.getMaxThreadCount()
146 + ", KEEP_ALIVE_SECS : " + this.getKeepAliveSecs()
147 + ", THREADS_READ_RESULTS : " + this.getThreadsReadResults()
148 + ", COMPLETION_QUEUE_SIZE : " + this.getCompletionQueueSize();
149 }
150 catch (HBqlException e) {
151 return "Invalid expression";
152 }
153 }
154 }