Reputation: 13
I don't understand why the callback in this code does not execute after Verticle has been successfully deployed?
public class VertxApp{
public static void main(String[] args) {
Vertx.vertx().deployVerticle(new MyVerticle(), res -> {
System.out.println(res.result());
});
}
}
The MyVerticle class:
public class MyVerticle extends AbstractVerticle {
@Override
public void start(Future<Void> startFuture) {
System.out.println("MyVerticle started!");
}
@Override
public void stop(Future stopFuture) throws Exception {
System.out.println("MyVerticle stopped!");
}
}
Upvotes: 0
Views: 65
Reputation: 1996
You never tell Vert.x
that you are finished with deployment. Vert.x
calls your MyVerticle.start(...)
with a Future<Void> startFuture
. You need to call startFuture.complete()
after you are done with the initialisation. Same for MyVerticle.stop(...)
.
class MyVerticle extends AbstractVerticle {
@Override
public void start(Future<Void> startFuture) {
System.out.println("MyVerticle started!");
startFuture.complete();
}
@Override
public void stop(Future stopFuture) throws Exception {
System.out.println("MyVerticle stopped!");
stopFuture.complete();
}
}
Or you could overwrite AbstractVerticle.start()
(without the Future
) like this:
class MyVerticle2 extends AbstractVerticle {
@Override
public void start() {
System.out.println("MyVerticle2 started!");
}
@Override
public void stop() throws Exception {
System.out.println("MyVerticle2 stopped!");
}
}
Upvotes: 1