diff --git a/virtual-threads-examples/src/main/java/io/vertx/example/virtualthreads/HttpClientExample.java b/virtual-threads-examples/src/main/java/io/vertx/example/virtualthreads/HttpClientExample.java index dd4a39292..3794512f6 100644 --- a/virtual-threads-examples/src/main/java/io/vertx/example/virtualthreads/HttpClientExample.java +++ b/virtual-threads-examples/src/main/java/io/vertx/example/virtualthreads/HttpClientExample.java @@ -18,18 +18,18 @@ public static void main(String[] args) throws Exception { @Override public void start() { - HttpServer server = vertx.createHttpServer(); + var server = vertx.createHttpServer(); server.requestHandler(request -> { request.response().end("Hello World"); }); await(server.listen(8080, "localhost")); // Make a simple HTTP request - HttpClient client = vertx.createHttpClient(); - HttpClientRequest req = await(client.request(HttpMethod.GET, 8080, "localhost", "/")); - HttpClientResponse resp = await(req.send()); - int status = resp.statusCode(); - Buffer body = await(resp.body()); + var client = vertx.createHttpClient(); + var req = await(client.request(HttpMethod.GET, 8080, "localhost", "/")); + var resp = await(req.send()); + var status = resp.statusCode(); + var body = await(resp.body()); System.out.println("Got response status=" + status + " body='" + body + "'"); } } diff --git a/virtual-threads-examples/src/main/java/io/vertx/example/virtualthreads/MovieRatingService.java b/virtual-threads-examples/src/main/java/io/vertx/example/virtualthreads/MovieRatingService.java index ab2c1f0d8..d23fd6171 100644 --- a/virtual-threads-examples/src/main/java/io/vertx/example/virtualthreads/MovieRatingService.java +++ b/virtual-threads-examples/src/main/java/io/vertx/example/virtualthreads/MovieRatingService.java @@ -18,7 +18,7 @@ public class MovieRatingService extends AbstractVerticle { public static void main(String[] args) throws Exception { - Vertx vertx = Vertx.vertx(); + var vertx = Vertx.vertx(); vertx.deployVerticle(MovieRatingService.class, new DeploymentOptions().setThreadingModel(ThreadingModel.VIRTUAL_THREAD)) .toCompletionStage() .toCompletableFuture() @@ -50,12 +50,12 @@ public void start() { .put("max_pool_size-loop", 30) ); - for (String statement : DB_STATEMENTS) { + DB_STATEMENTS.forEach(statement -> { await(client.query(statement).execute()); - } + }); // Build Vert.x Web router - Router router = Router.router(vertx); + var router = Router.router(vertx); router.get("/movie/:id").handler(this::getMovie); router.get("/rateMovie/:id").handler(this::rateMovie); router.get("/getRating/:id").handler(this::getRating); @@ -68,8 +68,8 @@ public void start() { // Send info about a movie private void getMovie(RoutingContext ctx) { - String id = ctx.pathParam("id"); - RowSet rows = await(client.preparedQuery("SELECT TITLE FROM MOVIE WHERE ID=?").execute(Tuple.of(id))); + var id = ctx.pathParam("id"); + var rows = await(client.preparedQuery("SELECT TITLE FROM MOVIE WHERE ID=?").execute(Tuple.of(id))); if (rows.size() == 1) { ctx.response() .putHeader("Content-Type", "application/json") @@ -84,8 +84,8 @@ private void getMovie(RoutingContext ctx) { // Rate a movie private void rateMovie(RoutingContext ctx) { - String movie = ctx.pathParam("id"); - int rating = Integer.parseInt(ctx.queryParam("rating").get(0)); + var movie = ctx.pathParam("id"); + var rating = Integer.parseInt(ctx.queryParam("rating").get(0)); RowSet rows = await(client.preparedQuery("SELECT TITLE FROM MOVIE WHERE ID=?").execute(Tuple.of(movie))); if (rows.size() == 1) { await(client.preparedQuery("INSERT INTO RATING (VALUE, MOVIE_ID) VALUES ?, ?").execute(Tuple.of(rating, movie))); @@ -97,8 +97,8 @@ private void rateMovie(RoutingContext ctx) { // Get the current rating of a movie private void getRating(RoutingContext ctx) { - String id = ctx.pathParam("id"); - RowSet rows = await(client.preparedQuery("SELECT AVG(VALUE) AS VALUE FROM RATING WHERE MOVIE_ID=?").execute(Tuple.of(id))); + var id = ctx.pathParam("id"); + var rows = await(client.preparedQuery("SELECT AVG(VALUE) AS VALUE FROM RATING WHERE MOVIE_ID=?").execute(Tuple.of(id))); ctx.response() .putHeader("Content-Type", "application/json") .end(new JsonObject() diff --git a/virtual-threads-examples/src/main/java/io/vertx/example/virtualthreads/SqlClientExample.java b/virtual-threads-examples/src/main/java/io/vertx/example/virtualthreads/SqlClientExample.java index 5d3b73f55..17ba8c07f 100644 --- a/virtual-threads-examples/src/main/java/io/vertx/example/virtualthreads/SqlClientExample.java +++ b/virtual-threads-examples/src/main/java/io/vertx/example/virtualthreads/SqlClientExample.java @@ -10,8 +10,8 @@ public class SqlClientExample extends AbstractVerticle { public static void main(String[] args) throws Exception { - Vertx vertx = Vertx.vertx(); - try (PostgreSQLContainer container = new PostgreSQLContainer<>()) { + var vertx = Vertx.vertx(); + try (var container = new PostgreSQLContainer<>()) { container.start(); vertx.deployVerticle(() -> { PgConnectOptions connectOptions = new PgConnectOptions() @@ -42,7 +42,7 @@ public void start() { // insert some test data await(pool.query("insert into test values (1, 'Hello'), (2, 'World')").execute()); // query some data - RowSet rows = await(pool.query("select * from test").execute()); + var rows = await(pool.query("select * from test").execute()); for (Row row : rows) { System.out.println("row = " + row.toJson()); } diff --git a/virtual-threads-examples/src/main/java/io/vertx/example/virtualthreads/WebClientExample.java b/virtual-threads-examples/src/main/java/io/vertx/example/virtualthreads/WebClientExample.java index deb152bbe..9ff4df76a 100644 --- a/virtual-threads-examples/src/main/java/io/vertx/example/virtualthreads/WebClientExample.java +++ b/virtual-threads-examples/src/main/java/io/vertx/example/virtualthreads/WebClientExample.java @@ -15,7 +15,7 @@ public class WebClientExample extends AbstractVerticle { public static void main(String[] args) throws Exception { - Vertx vertx = Vertx.vertx(); + var vertx = Vertx.vertx(); vertx.deployVerticle(WebClientExample.class, new DeploymentOptions() .setThreadingModel(ThreadingModel.VIRTUAL_THREAD)) .toCompletionStage() @@ -25,20 +25,20 @@ public static void main(String[] args) throws Exception { @Override public void start() { - HttpServer server = vertx.createHttpServer(); + var server = vertx.createHttpServer(); server.requestHandler(request -> { request.response().end("Hello World"); }); await(server.listen(8080, "localhost")); // Make a simple HTTP request - WebClient client = WebClient.create(vertx); - HttpResponse resp = await(client + var client = WebClient.create(vertx); + var resp = await(client .get(8080, "localhost", "/") .expect(ResponsePredicate.SC_OK) .send()); - int status = resp.statusCode(); - Buffer body = resp.body(); + var status = resp.statusCode(); + var body = resp.body(); System.out.println("Got response status=" + status + " body='" + body + "'"); } }