Skip to content

Commit

Permalink
Migrate to VerticleBase in module examples
Browse files Browse the repository at this point in the history
See vert-x3/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 <[email protected]>
  • Loading branch information
tsegismont committed Nov 20, 2024
1 parent 14e9377 commit 1a28a6f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions vertx-core/src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 7 additions & 4 deletions vertx-core/src/main/java/examples/NetExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -172,20 +175,20 @@ 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 -> {
// Just echo back the data
socket.write(buffer);
});
});
server.listen(1234, "localhost");
return server.listen(1234, "localhost");
}
}

Expand Down

0 comments on commit 1a28a6f

Please sign in to comment.