-
Notifications
You must be signed in to change notification settings - Fork 5
/
Runner.java
253 lines (210 loc) · 7.28 KB
/
Runner.java
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
package org.genericsystem.watch.beta;
import java.io.File;
import java.io.IOException;
import java.util.function.Consumer;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
public class Runner {
private static final String WEB_EXAMPLES_DIR = "web-examples";
private static final String WEB_EXAMPLES_JAVA_DIR = WEB_EXAMPLES_DIR + "/src/main/java/";
private static final String WEB_EXAMPLES_JS_DIR = WEB_EXAMPLES_DIR + "/src/main/js/";
private static final String WEB_EXAMPLES_GROOVY_DIR = WEB_EXAMPLES_DIR + "/src/main/groovy/";
private static final String WEB_EXAMPLES_RUBY_DIR = WEB_EXAMPLES_DIR + "/src/main/ruby/";
public static void runClusteredExample(Class clazz) {
runExample(WEB_EXAMPLES_JAVA_DIR, clazz, new VertxOptions().setClustered(true), null);
}
public static void runExample(Class clazz) {
runExample(WEB_EXAMPLES_JAVA_DIR, clazz, new VertxOptions().setClustered(false), null);
}
public static void runExample(Class clazz, DeploymentOptions options) {
runExample(WEB_EXAMPLES_JAVA_DIR, clazz, new VertxOptions().setClustered(false), options);
}
// JavaScript examples
public static void runJSExample(String scriptName) {
runScriptExample(WEB_EXAMPLES_JS_DIR, scriptName, new VertxOptions().setClustered(false));
}
public static void runJSExampleClustered(String scriptName) {
runScriptExample(WEB_EXAMPLES_JS_DIR, scriptName, new VertxOptions().setClustered(true));
}
static class JSAuthRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/web/auth/server.js");
}
}
static class JSAuthJDBC {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/web/authjdbc/server.js");
}
}
static class JSHelloWorldRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/web/helloworld/server.js");
}
}
static class JSRealtimeRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/web/realtime/server.js");
}
}
static class JSChatRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/web/chat/server.js");
}
}
static class JSSessionsRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/web/sessions/server.js");
}
}
static class JSTemplatingRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/web/templating/mvel/server.js");
}
}
// Groovy examples
public static void runGroovyExample(String scriptName) {
runScriptExample(WEB_EXAMPLES_GROOVY_DIR, scriptName, new VertxOptions().setClustered(false));
}
public static void runGroovyExampleClustered(String scriptName) {
runScriptExample(WEB_EXAMPLES_GROOVY_DIR, scriptName, new VertxOptions().setClustered(true));
}
static class GroovyAuthRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/web/auth/server.groovy");
}
}
static class GroovyAuthJDBC {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/web/authjdbc/server.groovy");
}
}
static class GroovyHelloWorldRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/web/helloworld/server.groovy");
}
}
static class GroovyChatRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/web/chat/server.groovy");
}
}
static class GroovyRealtimeRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/web/realtime/server.groovy");
}
}
static class GroovySessionsRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/web/sessions/server.groovy");
}
}
static class GroovyTemplatingRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/web/templating/mvel/server.groovy");
}
}
static class GroovyRestRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/web/rest/simple_rest.groovy");
}
}
// Ruby examples
public static void runRubyExample(String scriptName) {
runScriptExample(WEB_EXAMPLES_RUBY_DIR, scriptName, new VertxOptions().setClustered(false));
}
public static void runRubyExampleClustered(String scriptName) {
runScriptExample(WEB_EXAMPLES_RUBY_DIR, scriptName, new VertxOptions().setClustered(true));
}
static class RubyAuthRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/web/auth/server.rb");
}
}
static class RubyAuthJDBC {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/web/authjdbc/server.rb");
}
}
static class RubyHelloWorldRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/web/helloworld/server.rb");
}
}
static class RubyChatRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/web/chat/server.rb");
}
}
static class RubyRealtimeRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/web/realtime/server.rb");
}
}
static class RubySessionsRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/web/sessions/server.rb");
}
}
static class RubyTemplatingRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/web/templating/mvel/server.rb");
}
}
public static void runExample(String exampleDir, Class clazz, VertxOptions options,
DeploymentOptions deploymentOptions) {
runExample(exampleDir + clazz.getPackage().getName().replace(".", "/"), clazz.getName(), options,
deploymentOptions);
}
public static void runScriptExample(String prefix, String scriptName, VertxOptions options) {
File file = new File(scriptName);
String dirPart = file.getParent();
String scriptDir = prefix + dirPart;
runExample(scriptDir, scriptDir + "/" + file.getName(), options, null);
}
public static void runExample(String exampleDir, String verticleID, VertxOptions options,
DeploymentOptions deploymentOptions) {
if (options == null) {
// Default parameter
options = new VertxOptions();
}
// Smart cwd detection
// Based on the current directory (.) and the desired directory
// (exampleDir), we try to compute the vertx.cwd
// directory:
try {
// We need to use the canonical file. Without the file name is .
File current = new File(".").getCanonicalFile();
if (exampleDir.startsWith(current.getName()) && !exampleDir.equals(current.getName())) {
exampleDir = exampleDir.substring(current.getName().length() + 1);
}
} catch (IOException e) {
// Ignore it.
}
System.setProperty("vertx.cwd", exampleDir);
Consumer<Vertx> runner = vertx -> {
try {
if (deploymentOptions != null) {
vertx.deployVerticle(verticleID, deploymentOptions);
} else {
vertx.deployVerticle(verticleID);
}
} catch (Throwable t) {
t.printStackTrace();
}
};
if (options.isClustered()) {
Vertx.clusteredVertx(options, res -> {
if (res.succeeded()) {
Vertx vertx = res.result();
runner.accept(vertx);
} else {
res.cause().printStackTrace();
}
});
} else {
Vertx vertx = Vertx.vertx(options);
runner.accept(vertx);
}
}
}