-
Notifications
You must be signed in to change notification settings - Fork 5
/
Runner.java
560 lines (466 loc) · 16.4 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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
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;
/*
* @author <a href="http://tfox.org">Tim Fox</a>
*/
public class Runner {
private static final String CORE_EXAMPLES_DIR = "core-examples";
private static final String CORE_EXAMPLES_JAVA_DIR = CORE_EXAMPLES_DIR + "/src/main/java/";
private static final String CORE_EXAMPLES_JS_DIR = CORE_EXAMPLES_DIR + "/src/main/js/";
private static final String CORE_EXAMPLES_GROOVY_DIR = CORE_EXAMPLES_DIR + "/src/main/groovy/";
private static final String CORE_EXAMPLES_RUBY_DIR = CORE_EXAMPLES_DIR + "/src/main/ruby/";
public static void runClusteredExample(Class clazz) {
runExample(CORE_EXAMPLES_JAVA_DIR, clazz, new VertxOptions().setClustered(true), null);
}
public static void runClusteredExample(Class clazz, VertxOptions options) {
runExample(CORE_EXAMPLES_JAVA_DIR, clazz, options.setClustered(true), null);
}
public static void runExample(Class clazz) {
runExample(CORE_EXAMPLES_JAVA_DIR, clazz, new VertxOptions().setClustered(false), null);
}
public static void runExample(Class clazz, DeploymentOptions options) {
runExample(CORE_EXAMPLES_JAVA_DIR, clazz, new VertxOptions().setClustered(false), options);
}
// JavaScript examples
public static void runJSExample(String scriptName) {
runScriptExample(CORE_EXAMPLES_JS_DIR, scriptName, new VertxOptions().setClustered(false));
}
public static void runJSExampleClustered(String scriptName) {
runScriptExample(CORE_EXAMPLES_JS_DIR, scriptName, new VertxOptions().setClustered(true));
}
static class JSEchoServerRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/net/echo/server.js");
}
}
static class JSEchoClientRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/net/echo/client.js");
}
}
static class JSEchoSslServerRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/net/echossl/server.js");
}
}
static class JSEchoSslClientRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/net/echossl/client.js");
}
}
static class JSEventBusPointToPointReceiverRunner {
public static void main(String[] args) {
Runner.runJSExampleClustered("io/vertx/example/core/eventbus/pointtopoint/receiver.js");
}
}
static class JSEventBusPointToPointSenderRunner {
public static void main(String[] args) {
Runner.runJSExampleClustered("io/vertx/example/core/eventbus/pointtopoint/sender.js");
}
}
static class JSEventBusPubSubReceiverRunner {
public static void main(String[] args) {
Runner.runJSExampleClustered("io/vertx/example/core/eventbus/pubsub/receiver.js");
}
}
static class JSEventBusPubSubSenderRunner {
public static void main(String[] args) {
Runner.runJSExampleClustered("io/vertx/example/core/eventbus/pubsub/sender.js");
}
}
static class JSHttpsServerRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/http/https/server.js");
}
}
static class JSHttpsClientRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/http/https/client.js");
}
}
static class JSHttpProxyServerRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/http/proxy/server.js");
}
}
static class JSHttpProxyProxyRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/http/proxy/proxy.js");
}
}
static class JSHttpProxyClientRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/http/proxy/client.js");
}
}
static class JSHttpSendFileRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/http/sendfile/send_file.js");
}
}
static class JSHttpSimpleServerRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/http/simple/server.js");
}
}
static class JSHttpSimpleClientRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/http/simple/client.js");
}
}
static class JSHttpSimpleFormRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/http/simpleform/simple_form_server.js");
}
}
static class JSHttpSimpleFormUploadRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/http/simpleformupload/simple_form_upload_server.js");
}
}
static class JSHttpUploadServerRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/http/upload/server.js");
}
}
static class JSHttpUploadClientRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/http/upload/client.js");
}
}
static class JSHttpWebsocketsServerRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/http/websockets/server.js");
}
}
static class JSHttpWebsocketsClientRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/http/websockets/client.js");
}
}
static class JSVerticleAsyncStartRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/verticle/asyncstart/deploy_example.js");
}
}
static class JSVerticleDeployRunner {
public static void main(String[] args) {
Runner.runJSExample("io/vertx/example/core/verticle/deploy/deploy_example.js");
}
}
// Groovy examples
public static void runGroovyExample(String scriptName) {
runScriptExample(CORE_EXAMPLES_GROOVY_DIR, scriptName, new VertxOptions().setClustered(false));
}
public static void runGroovyExampleClustered(String scriptName) {
runScriptExample(CORE_EXAMPLES_GROOVY_DIR, scriptName, new VertxOptions().setClustered(true));
}
static class GroovyEchoServerRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/net/echo/server.groovy");
}
}
static class GroovyEchoClientRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/net/echo/client.groovy");
}
}
static class GroovyEchoSslServerRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/net/echossl/server.groovy");
}
}
static class GroovyEchoSslClientRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/net/echossl/client.groovy");
}
}
static class GroovyEventBusPointToPointReceiverRunner {
public static void main(String[] args) {
Runner.runGroovyExampleClustered("io/vertx/example/core/eventbus/pointtopoint/receiver.groovy");
}
}
static class GroovyEventBusPointToPointSenderRunner {
public static void main(String[] args) {
Runner.runGroovyExampleClustered("io/vertx/example/core/eventbus/pointtopoint/sender.groovy");
}
}
static class GroovyEventBusPubSubReceiverRunner {
public static void main(String[] args) {
Runner.runGroovyExampleClustered("io/vertx/example/core/eventbus/pubsub/receiver.groovy");
}
}
static class GroovyEventBusPubSubSenderRunner {
public static void main(String[] args) {
Runner.runGroovyExampleClustered("io/vertx/example/core/eventbus/pubsub/sender.groovy");
}
}
static class GroovyHttpsServerRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/http/https/server.groovy");
}
}
static class GroovyHttpsClientRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/http/https/client.groovy");
}
}
static class GroovyHttpProxyServerRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/http/proxy/server.groovy");
}
}
static class GroovyHttpProxyProxyRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/http/proxy/proxy.groovy");
}
}
static class GroovyHttpProxyClientRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/http/proxy/client.groovy");
}
}
static class GroovyHttpSendFileRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/http/sendfile/send_file.groovy");
}
}
static class GroovyHttpSimpleServerRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/http/simple/server.groovy");
}
}
static class GroovyHttpSimpleClientRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/http/simple/client.groovy");
}
}
static class GroovyHttpSimpleFormRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/http/simpleform/simple_form_server.groovy");
}
}
static class GroovyHttpSimpleFormUploadRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/http/simpleformupload/simple_form_upload_server.groovy");
}
}
static class GroovyHttpUploadServerRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/http/upload/server.groovy");
}
}
static class GroovyHttpUploadClientRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/http/upload/client.groovy");
}
}
static class GroovyHttpWebsocketsServerRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/http/websockets/server.groovy");
}
}
static class GroovyHttpWebsocketsClientRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/http/websockets/client.groovy");
}
}
static class GroovyVerticleAsyncStartRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/verticle/asyncstart/deploy_example.groovy");
}
}
static class GroovyVerticleDeployRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/verticle/deploy/deploy_example.groovy");
}
}
// Ruby examples
public static void runRubyExample(String scriptName) {
runScriptExample(CORE_EXAMPLES_RUBY_DIR, scriptName, new VertxOptions().setClustered(false));
}
public static void runRubyExampleClustered(String scriptName) {
runScriptExample(CORE_EXAMPLES_GROOVY_DIR, scriptName, new VertxOptions().setClustered(true));
}
static class RubyEchoServerRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/net/echo/server.rb");
}
}
static class RubyEchoClientRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/net/echo/client.rb");
}
}
static class RubyEchoSslServerRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/net/echossl/server.rb");
}
}
static class RubyEchoSslClientRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/net/echossl/client.rb");
}
}
static class RubyEventBusPointToPointReceiverRunner {
public static void main(String[] args) {
Runner.runRubyExampleClustered("io/vertx/example/core/eventbus/pointtopoint/receiver.rb");
}
}
static class RubyEventBusPointToPointSenderRunner {
public static void main(String[] args) {
Runner.runRubyExampleClustered("io/vertx/example/core/eventbus/pointtopoint/sender.rb");
}
}
static class RubyEventBusPubSubReceiverRunner {
public static void main(String[] args) {
Runner.runRubyExampleClustered("io/vertx/example/core/eventbus/pubsub/receiver.rb");
}
}
static class RubyEventBusPubSubSenderRunner {
public static void main(String[] args) {
Runner.runRubyExampleClustered("io/vertx/example/core/eventbus/pubsub/sender.rb");
}
}
static class RubyHttpsServerRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/http/https/server.rb");
}
}
static class RubyHttpsClientRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/http/https/client.rb");
}
}
static class RubyHttpProxyServerRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/http/proxy/server.rb");
}
}
static class RubyHttpProxyProxyRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/http/proxy/proxy.rb");
}
}
static class RubyHttpProxyClientRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/http/proxy/client.rb");
}
}
static class RubyHttpSendFileRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/http/sendfile/send_file.rb");
}
}
static class RubyHttpSimpleServerRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/http/simple/server.rb");
}
}
static class RubyHttpSimpleClientRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/http/simple/client.rb");
}
}
static class RubyHttpSimpleFormRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/http/simpleform/simple_form_server.rb");
}
}
static class RubyHttpSimpleFormUploadRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/http/simpleformupload/simple_form_upload_server.rb");
}
}
static class RubyHttpUploadServerRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/http/upload/server.rb");
}
}
static class RubyHttpUploadClientRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/http/upload/client.rb");
}
}
static class RubyHttpWebsocketsServerRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/http/websockets/server.rb");
}
}
static class RubyHttpWebsocketsClientRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/http/websockets/client.rb");
}
}
static class RubyVerticleAsyncStartRunner {
public static void main(String[] args) {
Runner.runRubyExample("io/vertx/example/core/verticle/asyncstart/deploy_example.rb");
}
}
static class RubyVerticleDeployRunner {
public static void main(String[] args) {
Runner.runGroovyExample("io/vertx/example/core/verticle/deploy/deploy_example.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);
}
}
}