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

Upgrade to Vert.x 5.0.0.CR3 #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions chapter1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
<version>1.0</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.relese>11</maven.compiler.relese>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<vertx.version>4.0.3</vertx.version>
<vertx.version>5.0.0.CR3</vertx.version>
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
<mainClass>chapter1.firstapp.VertxEcho</mainClass>
</properties>
Expand Down
2 changes: 2 additions & 0 deletions chapter13/heat-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

<build>
<plugins>
<!--
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
Expand Down Expand Up @@ -59,6 +60,7 @@
</container>
</configuration>
</plugin>
-->
</plugins>
</build>

Expand Down
14 changes: 8 additions & 6 deletions chapter13/heat-api/src/main/java/chapter13/api/HeatApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpResponseExpectation;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.client.HttpResponse;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.client.WebClientOptions;
import io.vertx.ext.web.client.predicate.ResponsePredicate;
import io.vertx.ext.web.codec.BodyCodec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -50,7 +50,7 @@ public void start(Promise<Void> startPromise) {

vertx.createHttpServer()
.requestHandler(router)
.listen(httpPort, ar -> {
.listen(httpPort).onComplete(ar -> {
if (ar.succeeded()) {
logger.info("HTTP server listening on port {}", httpPort);
startPromise.complete();
Expand All @@ -63,9 +63,10 @@ public void start(Promise<Void> startPromise) {
private void fetchData(RoutingContext routingContext, Consumer<HttpResponse<JsonObject>> action) {
webClient.get("/data")
.as(BodyCodec.jsonObject())
.expect(ResponsePredicate.SC_OK)
.timeout(5000)
.send(ar -> {
.send()
.expecting(HttpResponseExpectation.SC_OK)
.onComplete(ar -> {
if (ar.succeeded()) {
action.accept(ar.result());
} else {
Expand Down Expand Up @@ -114,9 +115,10 @@ private void livenessCheck(RoutingContext ctx) {

private void readinessCheck(RoutingContext ctx) {
webClient.get("/health")
.expect(ResponsePredicate.SC_OK)
.timeout(5000)
.send(ar -> {
.send()
.expecting(HttpResponseExpectation.SC_OK)
.onComplete(ar -> {
if (ar.succeeded()) {
logger.info("Readiness check complete");
ctx.response()
Expand Down
2 changes: 2 additions & 0 deletions chapter13/heat-sensor-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

<build>
<plugins>
<!--
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
Expand Down Expand Up @@ -65,6 +66,7 @@
</container>
</configuration>
</plugin>
-->
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public void start(Promise<Void> startPromise) {

vertx.createHttpServer()
.requestHandler(router)
.listen(httpPort, ar -> {
.listen(httpPort)
.onComplete(ar -> {
if (ar.succeeded()) {
logger.info("HTTP server listening on port {}", httpPort);
startPromise.complete();
Expand Down Expand Up @@ -97,7 +98,7 @@ public static void main(String[] args) throws UnknownHostException {
.setEventBusOptions(new EventBusOptions()
.setHost(ipv4)
.setClusterPublicHost(ipv4));
Vertx.clusteredVertx(options, ar -> {
Vertx.clusteredVertx(options).onComplete(ar -> {
if (ar.succeeded()) {
ar.result().deployVerticle(new HeatSensor());
} else {
Expand Down
5 changes: 2 additions & 3 deletions chapter13/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
</modules>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<vertx.version>4.0.3</vertx.version>
<vertx.version>5.0.0.CR3</vertx.version>
<logback-classic.version>1.2.3</logback-classic.version>
<jib-maven-plugin.version>2.4.0</jib-maven-plugin.version>
<hazelcast-kubernetes.version>2.0.1</hazelcast-kubernetes.version>
Expand Down
2 changes: 2 additions & 0 deletions chapter13/sensor-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

<build>
<plugins>
<!--
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
Expand Down Expand Up @@ -75,6 +76,7 @@
</container>
</configuration>
</plugin>
-->
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public void start(Promise<Void> startPromise) throws Exception {

vertx.createHttpServer()
.requestHandler(router)
.listen(httpPort, ar -> {
.listen(httpPort)
.onComplete(ar -> {
if (ar.succeeded()) {
logger.info("HTTP server listening on port {}", httpPort);
startPromise.complete();
Expand Down Expand Up @@ -94,7 +95,7 @@ public static void main(String[] args) throws UnknownHostException {
.setPublishQuantiles(true)
.setEnabled(true))
.setEnabled(true));
Vertx.clusteredVertx(options, ar -> {
Vertx.clusteredVertx(options).onComplete(ar -> {
if (ar.succeeded()) {
ar.result().deployVerticle(new Gateway());
} else {
Expand Down
5 changes: 2 additions & 3 deletions chapter2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
<version>1.0</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<vertx.version>4.0.3</vertx.version>
<vertx.version>5.0.0.CR3</vertx.version>
<logback-classic.version>1.2.3</logback-classic.version>
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
<mainClass>chapter2.hello.HelloVerticle</mainClass>
Expand Down
4 changes: 2 additions & 2 deletions chapter2/src/main/java/chapter2/deploy/Deployer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void start() {
}

private void deploy() {
vertx.deployVerticle(new EmptyVerticle(), ar -> { // <2>
vertx.deployVerticle(new EmptyVerticle()).onComplete(ar -> { // <2>
if (ar.succeeded()) {
String id = ar.result();
logger.info("Successfully deployed {}", id);
Expand All @@ -30,7 +30,7 @@ private void deploy() {
}

private void undeployLater(String id) {
vertx.undeploy(id, ar -> { // <4>
vertx.undeploy(id).onComplete(ar -> { // <4>
if (ar.succeeded()) {
logger.info("{} was undeployed", id);
} else {
Expand Down
14 changes: 5 additions & 9 deletions chapter2/src/main/java/chapter2/execblocking/Offload.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ public class Offload extends AbstractVerticle {
public void start() {
vertx.setPeriodic(5000, id -> {
logger.info("Tick");
vertx.executeBlocking(this::blockingCode, this::resultHandler);
vertx.executeBlocking(this::blockingCode).onComplete(this::resultHandler);
});
}

private void blockingCode(Promise<String> promise) {
private String blockingCode() throws Exception {
logger.info("Blocking code running");
try {
Thread.sleep(4000);
logger.info("Done!");
promise.complete("Ok!");
} catch (InterruptedException e) {
promise.fail(e);
}
Thread.sleep(4000);
logger.info("Done!");
return "Ok!";
}

private void resultHandler(AsyncResult<String> ar) {
Expand Down
3 changes: 2 additions & 1 deletion chapter2/src/main/java/chapter2/future/SomeVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class SomeVerticle extends AbstractVerticle {
public void start(Promise<Void> promise) { // <1>
vertx.createHttpServer()
.requestHandler(req -> req.response().end("Ok"))
.listen(8080, ar -> {
.listen(8080)
.onComplete(ar -> {
if (ar.succeeded()) { // <2>
promise.complete(); // <3>
} else {
Expand Down
3 changes: 2 additions & 1 deletion chapter2/src/main/java/chapter2/worker/WorkerVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import io.vertx.core.ThreadingModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -27,7 +28,7 @@ public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
DeploymentOptions opts = new DeploymentOptions()
.setInstances(2)
.setWorker(true);
.setThreadingModel(ThreadingModel.WORKER);
vertx.deployVerticle("chapter2.worker.WorkerVerticle", opts);
}
}
5 changes: 2 additions & 3 deletions chapter3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
<version>1.0</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<vertx.version>4.0.3</vertx.version>
<vertx.version>5.0.0.CR3</vertx.version>
<logback-classic.version>1.2.3</logback-classic.version>
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
<junit.jupiter.version>5.7.1</junit.jupiter.version>
Expand Down
8 changes: 3 additions & 5 deletions chapter3/src/main/java/chapter3/HttpServer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package chapter3;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.TimeoutStream;
import io.vertx.core.eventbus.MessageConsumer;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
Expand Down Expand Up @@ -40,9 +39,8 @@ private void sse(HttpServerRequest request) {
});


TimeoutStream ticks = vertx.periodicStream(1000);
ticks.handler(id -> {
vertx.eventBus().<JsonObject>request("sensor.average", "", reply -> {
long periodic = vertx.setPeriodic(1000, id -> {
vertx.eventBus().<JsonObject>request("sensor.average", "").onComplete(reply -> {
if (reply.succeeded()) {
response.write("event: average\n");
response.write("data: " + reply.result().body().encode() + "\n\n");
Expand All @@ -52,7 +50,7 @@ private void sse(HttpServerRequest request) {

response.endHandler(v -> {
consumer.unregister();
ticks.cancel();
vertx.cancelTimer(periodic);
});
}
}
2 changes: 1 addition & 1 deletion chapter3/src/main/java/chapter3/cluster/FirstInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class FirstInstance {
private static final Logger logger = LoggerFactory.getLogger(FirstInstance.class);

public static void main(String[] args) {
Vertx.clusteredVertx(new VertxOptions(), ar -> {
Vertx.clusteredVertx(new VertxOptions()).onComplete(ar -> {
if (ar.succeeded()) {
logger.info("First instance has been started");
Vertx vertx = ar.result();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class SecondInstance {
private static final Logger logger = LoggerFactory.getLogger(SecondInstance.class);

public static void main(String[] args) {
Vertx.clusteredVertx(new VertxOptions(), ar -> {
Vertx.clusteredVertx(new VertxOptions()).onComplete(ar -> {
if (ar.succeeded()) {
logger.info("Second instance has been started");
Vertx vertx = ar.result();
Expand Down
4 changes: 2 additions & 2 deletions chapter3/src/test/java/chapter3/SensorDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class SensorDataTest {
@Test
void testAverage(Vertx vertx, VertxTestContext ctx) {
EventBus bus = vertx.eventBus();
vertx.deployVerticle(new SensorData(), ctx.succeeding(id -> {
vertx.deployVerticle(new SensorData()).onComplete(ctx.succeeding(id -> {
bus.publish("sensor.updates", new JsonObject()
.put("id", "a").put("temp", 20.0d));
bus.publish("sensor.updates", new JsonObject()
.put("id", "b").put("temp", 22.0d));
bus.request("sensor.average", "", ctx.succeeding(reply -> ctx.verify(() -> {
bus.request("sensor.average", "").onComplete(ctx.succeeding(reply -> ctx.verify(() -> {
JsonObject json = (JsonObject) reply.body();
assertEquals(21.0d, (double) json.getDouble("average"));
ctx.completeNow();
Expand Down
5 changes: 2 additions & 3 deletions chapter4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
<version>1.0</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<vertx.version>4.0.3</vertx.version>
<vertx.version>5.0.0.CR3</vertx.version>
<logback-classic.version>1.2.3</logback-classic.version>
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
<mainClass>chapter4.jukebox.Main</mainClass>
Expand Down
6 changes: 3 additions & 3 deletions chapter4/src/main/java/chapter4/jukebox/Jukebox.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private enum State {PLAYING, PAUSED}
// --------------------------------------------------------------------------------- //

private void list(Message<?> request) {
vertx.fileSystem().readDir("tracks", ".*mp3$", ar -> {
vertx.fileSystem().readDir("tracks", ".*mp3$").onComplete(ar -> {
if (ar.succeeded()) {
List<String> files = ar.result()
.stream()
Expand Down Expand Up @@ -127,7 +127,7 @@ private void download(String path, HttpServerRequest request) {
return;
}
OpenOptions opts = new OpenOptions().setRead(true);
vertx.fileSystem().open(file, opts, ar -> {
vertx.fileSystem().open(file, opts).onComplete(ar -> {
if (ar.succeeded()) {
downloadFile(ar.result(), request);
} else {
Expand Down Expand Up @@ -178,7 +178,7 @@ private void streamAudioChunk(long id) {
if (currentFile == null) {
openNextFile();
}
currentFile.read(Buffer.buffer(4096), 0, positionInFile, 4096, ar -> {
currentFile.read(Buffer.buffer(4096), 0, positionInFile, 4096).onComplete(ar -> {
if (ar.succeeded()) {
processReadBuffer(ar.result());
} else {
Expand Down
2 changes: 1 addition & 1 deletion chapter4/src/main/java/chapter4/jukebox/NetControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void schedule(String command) {
}

private void listCommand(NetSocket socket) {
vertx.eventBus().request("jukebox.list", "", reply -> {
vertx.eventBus().request("jukebox.list", "").onComplete(reply -> {
if (reply.succeeded()) {
JsonObject data = (JsonObject) reply.result().body();
data.getJsonArray("files")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public static void main(String[] args) {
.appendInt(value.length())
.appendString(value);

file.end(buffer, ar -> vertx.close());
file.end(buffer).onComplete(ar -> vertx.close());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class VertxStreams {
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
OpenOptions opts = new OpenOptions().setRead(true);
vertx.fileSystem().open("build.gradle.kts", opts, ar -> {
vertx.fileSystem().open("build.gradle.kts", opts).onComplete(ar -> {
if (ar.succeeded()) {
AsyncFile file = ar.result();
file.handler(System.out::println)
Expand Down
Loading