From 1a28a6f0913802951dc5e6536dc99963f80b466a Mon Sep 17 00:00:00 2001 From: Thomas Segismont Date: Wed, 20 Nov 2024 18:14:43 +0100 Subject: [PATCH] Migrate to VerticleBase in module examples See https://github.com/vert-x3/issues/issues/649 There still are some examples with AbstractVerticle, but they don't need to migrated: either the start method is synchronous or pseudo-synchronous (virtual threads). Signed-off-by: Thomas Segismont --- vertx-core/src/main/asciidoc/index.adoc | 6 +++--- vertx-core/src/main/java/examples/NetExamples.java | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/vertx-core/src/main/asciidoc/index.adoc b/vertx-core/src/main/asciidoc/index.adoc index ffc69f956ef..e3e9e998be4 100644 --- a/vertx-core/src/main/asciidoc/index.adoc +++ b/vertx-core/src/main/asciidoc/index.adoc @@ -322,15 +322,15 @@ will automatically stop any running server when the verticle is un-deployed. === What happened to Vert.x 4 Verticle and AbstractVerticle contracts? -The contract defined by `Verticle` and `AbstractVerticle` was not adapted anymore to Vert.x 5 future based model +The contract defined by `Verticle` and `AbstractVerticle` wasn't convenient anymore with Vert.x 5 future based model: [source,java] ---- {@link examples.CoreExamples#verticleContract} ---- -`Verticle` and `AbstractVerticle` are not deprecated in Vert.x 5 and it is fine to use them, however it is not the default -recommended choice anymore. +Nevertheless, `Verticle` and `AbstractVerticle` are not deprecated in Vert.x 5. +It is fine to use them, however it is not the default recommended choice anymore. === Verticle Types diff --git a/vertx-core/src/main/java/examples/NetExamples.java b/vertx-core/src/main/java/examples/NetExamples.java index 9464a2263df..dfdca83a50f 100755 --- a/vertx-core/src/main/java/examples/NetExamples.java +++ b/vertx-core/src/main/java/examples/NetExamples.java @@ -12,7 +12,10 @@ package examples; import io.netty.handler.logging.ByteBufFormat; -import io.vertx.core.*; +import io.vertx.core.DeploymentOptions; +import io.vertx.core.Future; +import io.vertx.core.VerticleBase; +import io.vertx.core.Vertx; import io.vertx.core.buffer.Buffer; import io.vertx.core.http.ClientAuth; import io.vertx.core.http.HttpServer; @@ -172,12 +175,12 @@ public void example10(NetSocket socket) { public void example11(Vertx vertx) { - class MyVerticle extends AbstractVerticle { + class MyVerticle extends VerticleBase { NetServer server; @Override - public void start() throws Exception { + public Future start() { server = vertx.createNetServer(); server.connectHandler(socket -> { socket.handler(buffer -> { @@ -185,7 +188,7 @@ public void start() throws Exception { socket.write(buffer); }); }); - server.listen(1234, "localhost"); + return server.listen(1234, "localhost"); } }