Skip to content

Commit 237b67e

Browse files
committed
Provide examples of the different format of groovy verticles we support.
1 parent 25d64c3 commit 237b67e

File tree

6 files changed

+101
-0
lines changed

6 files changed

+101
-0
lines changed

core-examples/README.adoc

+20
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,24 @@ export NODE_PATH=$PWD
362362
vertx run my_npm_verticle.js
363363
----
364364

365+
== Groovy verticles
366+
367+
Vert.x supports several _formats_ to develop verticles in Groovy. This link:src/main/groovy/verticles[directory]
368+
illustrates the different formats:
369+
370+
* link:src/main/groovy/verticles/script.groovy[plain script] - a verticle developed as a plain Groovy script
371+
* link:src/main/groovy/verticles/script-with-hooks.groovy[plain script with hooks] - a verticle developed as a script
372+
with hooks called by vert.x when the verticle is deployed and un-deployed
373+
* link:src/main/groovy/verticles/verticle-extending-abstract-verticle.groovy[class extending AbstractVerticle] - a
374+
verticle developed as a class extending `AbstractVerticle`
375+
* link:src/main/groovy/verticles/verticle-extending-groovy-verticle.groovy[class extending GroovyVerticle] - a
376+
verticle developed as a class extending `GroovyVerticle`
377+
378+
You can run these examples using the `vertx` command line. For example:
379+
380+
```
381+
vertx run script.groovy
382+
```
383+
384+
365385

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This directory contains examples of the different _formats_ supported to develop Groovy verticles.
2+
**Do not remove**, the files are not generated.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* A verticle developed as a groovy script with hooks. vert.x calls the `vertxStart` and `vertxStop` method when the verticle
3+
* is deployed and un-deployed.
4+
* @author <a href="http://escoffier.me">Clement Escoffier</a>
5+
*/
6+
7+
void vertxStart() {
8+
println "starting"
9+
vertx.createHttpServer().requestHandler({ request ->
10+
request.response().end("Hello world")
11+
}).listen(8080)
12+
13+
}
14+
15+
void vertxStop() {
16+
println "stopping"
17+
}
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* A verticle developed as a plain groovy script. The code is executed in the Vert.x Event Loop
3+
* @author <a href="http://escoffier.me">Clement Escoffier</a>
4+
*/
5+
6+
7+
println "Starting from " + Thread.currentThread().name
8+
9+
vertx.createHttpServer().requestHandler({ request ->
10+
request.response().end("Hello world")
11+
}).listen(8080)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import io.vertx.core.AbstractVerticle
2+
3+
/**
4+
* A verticle developed as class extending `AbstractVerticle`.
5+
* @author <a href="http://escoffier.me">Clement Escoffier</a>
6+
*/
7+
8+
class MyVerticle extends AbstractVerticle {
9+
10+
@Override
11+
void start() throws Exception {
12+
println "starting"
13+
14+
vertx.createHttpServer().requestHandler({ request ->
15+
request.response().end("Hello world")
16+
}).listen(8080)
17+
}
18+
19+
@Override
20+
void stop() throws Exception {
21+
println "stopping"
22+
}
23+
}
24+
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import io.vertx.lang.groovy.GroovyVerticle
2+
3+
/**
4+
* A verticle developed as class extending `GroovyVerticle`.
5+
* @author <a href="http://escoffier.me">Clement Escoffier</a>
6+
*/
7+
8+
class MyVerticle extends GroovyVerticle {
9+
10+
@Override
11+
void start() throws Exception {
12+
println "starting"
13+
14+
vertx.createHttpServer().requestHandler({ request ->
15+
request.response().end("Hello world")
16+
}).listen(8080)
17+
}
18+
19+
@Override
20+
void stop() throws Exception {
21+
println "stopping"
22+
}
23+
}
24+
25+

0 commit comments

Comments
 (0)