forked from actframework/actframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActConfigKey.java
More file actions
184 lines (160 loc) · 5.2 KB
/
ActConfigKey.java
File metadata and controls
184 lines (160 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package act.conf;
/*-
* #%L
* ACT Framework
* %%
* Copyright (C) 2014 - 2017 ActFramework
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import act.Act;
import org.osgl.logging.L;
import org.osgl.logging.Logger;
import org.osgl.util.S;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* {@link Act} configuration keys. General rules:
* <p/>
* <ul>
* <li>When a key is ended with <code>.enabled</code>, then you should be able to set
* the setting without <code>.enabled</code> or replace it with <code>.disabled</code>
* but the value will be inverted. For example, <code>built_in.transformer.enabled</code>
* is equal to <code>built_in.transformer</code> and invert to
* <code>built_in.transformer.disabled</code></li>
* <p/>
* <li>When a key is ended with <code>.impl</code>, then you can either put an instance into
* the configuration map or a string of the class className</li>
* </ul>
*/
public enum ActConfigKey implements ConfigKey {
/**
* {@code act.home.dir} specifies the Act home dir
* <p>This property must be set to start Act. There is no default value for this configuration</p>
*/
HOME("home.dir"),
/**
* {@code act.app.base} specifies the application base in relation to the
* {@link #HOME home dir}.
* <p>Default value: {@code apps}</p>
*/
APP_BASE("app.base", "apps"),
/**
* {@code act.mode} specifies the Act running mode. Options:
* <ul>
* <li>{@code dev} - run Act during development, loading and refreshing class
* directly from srccode code enabled in this mode</li>
* <li>{@code prod} - run Act when system is live</li>
* </ul>
* <p>You pass the mode to Act runtime during start up like:</p>
* <pre><code>act --mode dev</code></pre>
* <p>Or via JVM properties like:</p>
* <pre><code>-Dmode=uat</code></pre>
*/
MODE("mode", Act.Mode.PROD),
/**
* `act.xio.worker_threads.max`
*
* specifies the maximum number of worker threads shall be created.
*
* Default value: `0` meaning let the system decide the worker_threads number
*/
XIO_MAX_WORKER_THREADS("xio.worker_threads.max.int"),
/**
* `act.xio.statistics.enabled`
*
* Enable/disable XIO statistics (for undertow only)
*
* Default value: `false`
*/
XIO_STATISTICS("xio.statistics.enabled"),
/**
* {@code act.xio.impl} specifies the implementation for the network stack implementation
*/
NETWORK_SERVER_IMPL("xio.impl");
private static Logger logger = L.get(AppConfigKey.class);
private static ConfigKeyHelper helper = new ConfigKeyHelper(Act.F.MODE_ACCESSOR, Act.class.getClassLoader());
private String key;
private Object defVal;
ActConfigKey(String key) {
this(key, null);
}
ActConfigKey(String key, Object defVal) {
this.key = Config.canonical(key);
this.defVal = defVal;
}
/**
* Return the key string
*
* @return the key of the configuration
*/
public String key() {
return key;
}
/**
* Return default value of this setting. The configuration data map
* is passed in in case the default value be variable depending on
* another setting.
*
* @param configuration
* @return return the default value
*/
protected Object getDefVal(Map<String, ?> configuration) {
return defVal;
}
/**
* Calling to this method is equals to calling {@link #key()}
*
* @return key of the configuration
*/
@Override
public String toString() {
return key;
}
@Override
public Object defVal() {
return defVal;
}
public <T> List<T> implList(String key, Map<String, ?> configuration, Class<T> c) {
return helper.getImplList(key, configuration, c);
}
/**
* Return configuration value from the configuration data map using the {@link #key}
* of this {@link AppConfigKey setting} instance
*
* @param configuration
* @param <T>
* @return return the configuration
*/
public <T> T val(Map<String, ?> configuration) {
return helper.getConfiguration(this, configuration);
}
private static Map<String, ActConfigKey> lookup = new HashMap<>(50);
static {
for (ActConfigKey k : values()) {
lookup.put(k.key(), k);
}
}
/**
* Return key enum instance from the string in case insensitive mode
*
* @param s
* @return configuration key from the string
*/
public static ActConfigKey valueOfIgnoreCase(String s) {
if (S.empty(s)) throw new IllegalArgumentException();
return lookup.get(Config.canonical(s));
}
}