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.AsyncExecutorManager;
24 import org.apache.hadoop.hbase.hbql.client.HBqlException;
25
26 import java.util.List;
27
28 public class AsyncExecutorDefinition {
29
30 private final String name;
31 private final List<ExecutorProperty> executorPropertyList;
32
33 private ExecutorProperty minThreadCount = null;
34 private ExecutorProperty maxThreadCount = null;
35 private ExecutorProperty keepAliveSecs = null;
36
37 public AsyncExecutorDefinition(final String name, final List<ExecutorProperty> executorPropertyList) {
38 this.name = name;
39 this.executorPropertyList = executorPropertyList;
40 }
41
42 public String getName() {
43 return this.name;
44 }
45
46 private List<ExecutorProperty> getExecutorPropertyList() {
47 return this.executorPropertyList;
48 }
49
50 private ExecutorProperty validateProperty(final ExecutorProperty assignee,
51 final ExecutorProperty value) throws HBqlException {
52 if (assignee != null)
53 throw new HBqlException("Multiple " + value.getPropertyType().getDescription()
54 + " values for " + this.getName() + " not allowed");
55 return value;
56 }
57
58 public void validatePropertyList() throws HBqlException {
59
60 if (this.getExecutorPropertyList() == null)
61 return;
62
63 for (final ExecutorProperty executorProperty : this.getExecutorPropertyList()) {
64
65 executorProperty.validate();
66
67 switch (executorProperty.getEnumType()) {
68
69 case MIN_THREAD_COUNT:
70 this.minThreadCount = this.validateProperty(this.minThreadCount, executorProperty);
71 break;
72
73 case MAX_THREAD_COUNT:
74 this.maxThreadCount = this.validateProperty(this.maxThreadCount, executorProperty);
75 break;
76
77 case KEEP_ALIVE_SECS:
78 this.keepAliveSecs = this.validateProperty(this.keepAliveSecs, executorProperty);
79 break;
80 }
81 }
82 }
83
84 public int getMinThreadCount() throws HBqlException {
85 if (this.minThreadCount != null)
86 return this.minThreadCount.getIntegerValue();
87 else
88 return AsyncExecutorManager.defaultMinThreadCount;
89 }
90
91 public int getMaxThreadCount() throws HBqlException {
92 if (this.maxThreadCount != null)
93 return this.maxThreadCount.getIntegerValue();
94 else
95 return AsyncExecutorManager.defaultMaxThreadCount;
96 }
97
98 public long getKeepAliveSecs() throws HBqlException {
99 if (this.keepAliveSecs != null)
100 return this.keepAliveSecs.getIntegerValue();
101 else
102 return AsyncExecutorManager.defaultKeepAliveSecs;
103 }
104
105 public String asString() {
106 try {
107 return " MIN_THREAD_COUNT : " + this.getMinThreadCount()
108 + ", MAX_THREAD_COUNT : " + this.getMaxThreadCount()
109 + ", KEEP_ALIVE_SECS : " + this.getKeepAliveSecs();
110 }
111 catch (HBqlException e) {
112 return "Invalid expression";
113 }
114 }
115 }