Anatomy of a verticle

The verticle for our wiki consists of a single io.vertx.guides.wiki.MainVerticle Java class. This class extends io.vertx.core.AbstractVerticle, the base class for verticles that mainly provides:

  1. life-cycle start and stop methods to override,

  2. a protected field called vertx that references the Vert.x environment where the verticle is being deployed,

  3. an accessor to some configuration object that allows passing external configuration to a verticle.

To get started our verticle can just override the start method as follows:

  1. public class MainVerticle extends AbstractVerticle {
  2. @Override
  3. public void start(Promise<Void> promise) {
  4. promise.complete();
  5. }
  6. }

There are 2 forms of start (and stop) methods: 1 with no argument and 1 with a promise object reference. The no-argument variants imply that the verticle initialization or house-keeping phases always succeed unless an exception is being thrown. The variants with a promise object provide a more fine-grained approach to eventually signal that operations succeeded or not. Indeed, some initialization or cleanup code may require asynchronous operations, so reporting via a promise object naturally fits with asynchronous idioms.

Note
A promise has a future() method which eventually holds the result of an asynchronous operation.