forked from vert-x3/vertx-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OtherVerticle.java
48 lines (30 loc) · 1.38 KB
/
OtherVerticle.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
package io.vertx.example.core.verticle.asyncstart;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
/*
* @author <a href="http://tfox.org">Tim Fox</a>
*/
public class OtherVerticle extends AbstractVerticle {
@Override
public void start(Future<Void> startFuture) throws Exception {
System.out.println("In OtherVerticle.start (async)");
// This verticle takes some time to start (maybe it has to deploy other verticles or whatever)
// So we override the async version of start(), then we can mark the verticle as started some time later
// when all the slow startup is done, without blocking the actual start method.
// We simulate this long startup time by setting a timer
vertx.setTimer(2000, tid -> {
// Now everything is started, we can tell Vert.x this verticle is started then it will call the deploy handler
// of the caller that originally deployed it
System.out.println("Startup tasks are now complete, OtherVerticle is now started!");
startFuture.complete();
});
}
@Override
public void stop(Future<Void> stopFuture) throws Exception {
// If you have slow cleanup tasks to perform, you can similarly override the async stop method
vertx.setTimer(2000, tid -> {
System.out.println("Cleanup tasks are now complete, OtherVerticle is now stopped!");
stopFuture.complete();
});
}
}