io.vertx.core

## Class AbstractVerticle

- java.lang.Object
- - io.vertx.core.AbstractVerticle

- All Implemented Interfaces:
    Verticle
  Direct Known Subclasses:
    AbstractVerticle, AbstractVerticle, ConsulServiceVerticle, MailServiceVerticle, MongoServiceVerticle, ScriptVerticle, ShellVerticle, SyncVerticle

      public abstract class AbstractVerticle
      extends Object
      implements Verticle

  An abstract base class that you can extend to write your own Verticle classes.

  Instead of implementing `Verticle` directly, it is often simpler to just extend this class.

  In the simplest case, just override the `Verticle.start(Promise)` method. If you have verticle clean-up to do you can optionally override the `Verticle.stop(Promise)` method too.

  If your verticle does extra start-up or clean-up that takes some time (e.g. it deploys other verticles) then you should override the asynchronous `start` and `stop` methods.

  This class also maintains references to the `Vertx` and `Context` instances of the verticle for easy access.

  It also provides methods for getting the `verticle configuration`, `process arguments`, and `deployment ID`.

  Author:
    Tim Fox

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Context` | `context` Reference to the context of the verticle
    `protected Vertx` | `vertx` Reference to the Vert.x instance that deployed this verticle

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractVerticle()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `JsonObject` | `config()` Get the configuration of the verticle.
    `String` | `deploymentID()` Get the deployment ID of the verticle deployment
    `Vertx` | `getVertx()` Get the Vert.x instance
    `void` | `init(Vertx vertx, Context context)` Initialise the verticle.
    `List<String>` | `processArgs()` Get the arguments used when deploying the Vert.x process.
    `void` | `start()` If your verticle does a simple, synchronous start-up then override this method and put your start-up code in here.
    `void` | `start(Future<Void> startFuture)` Deprecated. Override `Verticle.start(Promise)` instead.
    `void` | `stop()` If your verticle has simple synchronous clean-up tasks to complete then override this method and put your clean-up code in here.
    `void` | `stop(Future<Void> stopFuture)` Deprecated. Override `Verticle.stop(Promise)` instead.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface io.vertx.core.Verticle

      `start, stop`

- - ### Field Detail

    - #### vertx

          protected Vertx vertx

      Reference to the Vert.x instance that deployed this verticle

    - #### context

          protected Context context

      Reference to the context of the verticle

  - ### Constructor Detail

    - #### AbstractVerticle

          public AbstractVerticle()

  - ### Method Detail

    - #### getVertx

          public Vertx getVertx()

      Get the Vert.x instance
      Specified by:
        `getVertx` in interface `Verticle`
      Returns:
        the Vert.x instance

    - #### init

          public void init(Vertx vertx,
                           Context context)

      Initialise the verticle.

      This is called by Vert.x when the verticle instance is deployed. Don't call it yourself.

      Specified by:
        `init` in interface `Verticle`
      Parameters:
        `vertx` - the deploying Vert.x instance
        `context` - the context of the verticle

    - #### deploymentID

          public String deploymentID()

      Get the deployment ID of the verticle deployment
      Returns:
        the deployment ID

    - #### config

          public JsonObject config()

      Get the configuration of the verticle.

      This can be specified when the verticle is deployed.

      Returns:
        the configuration

    - #### processArgs

          public List<String> processArgs()

      Get the arguments used when deploying the Vert.x process.
      Returns:
        the list of arguments

    - #### start

          @Deprecated
          public void start(Future<Void> startFuture)
                                 throws Exception

      Deprecated. Override `Verticle.start(Promise)` instead.
      Start the verticle.

      This is called by Vert.x when the verticle instance is deployed. Don't call it yourself.

      If your verticle does things in its startup which take some time then you can override this method and call the startFuture some time later when start up is complete.

      Specified by:
        `start` in interface `Verticle`
      Parameters:
        `startFuture` - a future which should be called when verticle start-up is complete.
      Throws:
        `Exception`

    - #### stop

          @Deprecated
          public void stop(Future<Void> stopFuture)
                                throws Exception

      Deprecated. Override `Verticle.stop(Promise)` instead.
      Stop the verticle.

      This is called by Vert.x when the verticle instance is un-deployed. Don't call it yourself.

      If your verticle does things in its shut-down which take some time then you can override this method and call the stopFuture some time later when clean-up is complete.

      Specified by:
        `stop` in interface `Verticle`
      Parameters:
        `stopFuture` - a future which should be called when verticle clean-up is complete.
      Throws:
        `Exception`

    - #### start

          public void start()
                     throws Exception

      If your verticle does a simple, synchronous start-up then override this method and put your start-up code in here.
      Throws:
        `Exception`

    - #### stop

          public void stop()
                    throws Exception

      If your verticle has simple synchronous clean-up tasks to complete then override this method and put your clean-up code in here.
      Throws:
        `Exception`

Copyright © 2021 Eclipse. All rights reserved.