From 5b0ef4830206692d3c85736f0cc74021767bb575 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Fri, 13 May 2022 11:29:45 +0300 Subject: [PATCH] Get rid of a lambda in Vertx runtime code --- .../vertx/http/runtime/VertxHttpRecorder.java | 95 ++++++++++--------- .../vertx/core/runtime/VertxCoreRecorder.java | 4 +- 2 files changed, 52 insertions(+), 47 deletions(-) diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java index 0db6c43879485..1bc55d1a46f21 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java @@ -1174,60 +1174,63 @@ public void handle(Void event) { } }); } - httpServer.listen(options.getPort(), options.getHost(), event -> { - if (event.cause() != null) { - startFuture.fail(event.cause()); - } else { - // Port may be random, so set the actual port - int actualPort = event.result().actualPort(); - - if (https) { - actualHttpsPort = actualPort; + httpServer.listen(options.getPort(), options.getHost(), new Handler<>() { + @Override + public void handle(AsyncResult event) { + if (event.cause() != null) { + startFuture.fail(event.cause()); } else { - actualHttpPort = actualPort; - } - if (remainingCount.decrementAndGet() == 0) { - //make sure we only set the properties once - if (actualPort != options.getPort()) { - // Override quarkus.http(s)?.(test-)?port - String schema; - if (https) { - clearHttpsProperty = true; - schema = "https"; - } else { - clearHttpProperty = true; - actualHttpPort = actualPort; - schema = "http"; - } - portPropertiesToRestore = new HashMap<>(); - String portPropertyValue = String.valueOf(actualPort); - //we always set the .port property, even if we are in test mode, so this will always - //reflect the current port - String portPropertyName = "quarkus." + schema + ".port"; - String prevPortPropertyValue = System.setProperty(portPropertyName, portPropertyValue); - if (!Objects.equals(prevPortPropertyValue, portPropertyValue)) { - portPropertiesToRestore.put(portPropertyName, prevPortPropertyValue); - } - if (launchMode == LaunchMode.TEST) { - //we also set the test-port property in a test - String testPropName = "quarkus." + schema + ".test-port"; - String prevTestPropPrevValue = System.setProperty(testPropName, portPropertyValue); - if (!Objects.equals(prevTestPropPrevValue, portPropertyValue)) { - portPropertiesToRestore.put(testPropName, prevTestPropPrevValue); + // Port may be random, so set the actual port + int actualPort = event.result().actualPort(); + + if (https) { + actualHttpsPort = actualPort; + } else { + actualHttpPort = actualPort; + } + if (remainingCount.decrementAndGet() == 0) { + //make sure we only set the properties once + if (actualPort != options.getPort()) { + // Override quarkus.http(s)?.(test-)?port + String schema; + if (https) { + clearHttpsProperty = true; + schema = "https"; + } else { + clearHttpProperty = true; + actualHttpPort = actualPort; + schema = "http"; } - } - if (launchMode.isDevOrTest()) { - // set the profile property as well to make sure we don't have any inconsistencies - portPropertyName = propertyWithProfilePrefix(portPropertyName); - prevPortPropertyValue = System.setProperty(portPropertyName, portPropertyValue); + portPropertiesToRestore = new HashMap<>(); + String portPropertyValue = String.valueOf(actualPort); + //we always set the .port property, even if we are in test mode, so this will always + //reflect the current port + String portPropertyName = "quarkus." + schema + ".port"; + String prevPortPropertyValue = System.setProperty(portPropertyName, portPropertyValue); if (!Objects.equals(prevPortPropertyValue, portPropertyValue)) { portPropertiesToRestore.put(portPropertyName, prevPortPropertyValue); } + if (launchMode == LaunchMode.TEST) { + //we also set the test-port property in a test + String testPropName = "quarkus." + schema + ".test-port"; + String prevTestPropPrevValue = System.setProperty(testPropName, portPropertyValue); + if (!Objects.equals(prevTestPropPrevValue, portPropertyValue)) { + portPropertiesToRestore.put(testPropName, prevTestPropPrevValue); + } + } + if (launchMode.isDevOrTest()) { + // set the profile property as well to make sure we don't have any inconsistencies + portPropertyName = propertyWithProfilePrefix(portPropertyName); + prevPortPropertyValue = System.setProperty(portPropertyName, portPropertyValue); + if (!Objects.equals(prevPortPropertyValue, portPropertyValue)) { + portPropertiesToRestore.put(portPropertyName, prevPortPropertyValue); + } + } } + startFuture.complete(null); } - startFuture.complete(null); - } + } } }); } diff --git a/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java b/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java index 64c87794043ec..5f7dab2f77732 100644 --- a/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java +++ b/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java @@ -421,7 +421,9 @@ private static void initializeClusterOptions(VertxConfiguration conf, VertxOptio if (cluster.port.isPresent()) { options.getEventBusOptions().setPort(cluster.port.getAsInt()); } - cluster.publicHost.ifPresent(options.getEventBusOptions()::setClusterPublicHost); + if (cluster.publicHost.isPresent()) { + options.getEventBusOptions().setClusterPublicHost(cluster.publicHost.get()); + } if (cluster.publicPort.isPresent()) { options.getEventBusOptions().setPort(cluster.publicPort.getAsInt()); }