public abstract class AbstractVerticle extends Object implements Verticle
Instead of implementing Verticle
directly, it is often simpler to just extend this class.
In the simplest case, just override the start(Promise)
method. If you have verticle clean-up to do you can
optionally override the 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
.
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 and Description |
---|
AbstractVerticle() |
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(Promise<Void> startPromise)
Start the verticle.
|
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(Promise<Void> stopPromise)
Stop the verticle.
|
protected Vertx vertx
protected Context context
public Vertx getVertx()
public void init(Vertx vertx, Context context)
This is called by Vert.x when the verticle instance is deployed. Don't call it yourself.
public String deploymentID()
public JsonObject config()
This can be specified when the verticle is deployed.
public List<String> processArgs()
public void start(Promise<Void> startPromise) throws Exception
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.
public void stop(Promise<Void> stopPromise) throws Exception
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.
public void start() throws Exception
Exception
Copyright © 2024 Eclipse. All rights reserved.