Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Future based Verticle deployment contract #5318

Merged
merged 6 commits into from
Sep 14, 2024
Merged

Future based Verticle deployment contract #5318

merged 6 commits into from
Sep 14, 2024

Conversation

vietj
Copy link
Member

@vietj vietj commented Sep 13, 2024

Motivation

Vert.x 4 has introduced a future based programming model, yet the Verticle and AbstractVerticle contracts doe not leverage this model for writing deployments. In addition the current API only provides anonymous classes preventing use cases where a simple lambda would fit.

Changes

Introduce a new io.vertx.core.Deployable interface:

@FunctionnalInterface
public interfacer Deployable {
  Future<?> deploy(Context context);
  default Future<?> undeploy(Context context) { /* implementation */ }
}

New deploy methods are added to Vertx providing

vertx.deployVerticle(context -> vertx
  .createHttpServer()
  .requestHandler(req -> req.response().end())
  .listen(port, host));

In addition Verticle extends now Deployable and Vertx only needs to handle deployments of Deployable.

A new VerticleBase class can be used as a replacement of AbstractVerticle:

public abstract class VerticleBase implements Deployable {

  /**
   * Reference to the Vert.x instance that deployed this verticle
   */
  protected Vertx vertx;

  /**
   * Reference to the context of the verticle
   */
  protected Context context;

  public void init(Vertx vertx, Context context) {
    this.vertx = vertx;
    this.context = context;
  }

  public String deploymentID() {
    return context.deploymentID();
  }

  public JsonObject config() {
    return context.config();
  }

  ...

  public Future<?> start() throws Exception { ... }
  public Future<?> stop() throws Exception { ... }
}

Users migrating to VerticleBase need to change the the base class of their verticle and return a Future<?> instead of completing a promise or returning void (they can return super.start()).

Verticle and AbstractVerticle are not deprecated but we do not encourage anymore to use these contracts.

The VerticleFactory contract has been updated to provide the ability to deploy vanilla deployable.

@vietj vietj added this to the 5.0.0 milestone Sep 14, 2024
@vietj vietj self-assigned this Sep 14, 2024
@vietj vietj marked this pull request as ready for review September 14, 2024 11:41
@vietj vietj changed the title Deployment Future based Verticle deployment contract Sep 14, 2024
@vietj vietj merged commit 2aeeec5 into master Sep 14, 2024
7 checks passed
@vietj vietj deleted the deployment branch September 14, 2024 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant