0

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!");
}
}

1 Answer 1

1

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!");
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.