From ebe28c27e446ec40395512bebc28ff3b2bc00a70 Mon Sep 17 00:00:00 2001 From: Marc-Olivier Fleury Date: Fri, 20 Sep 2019 14:26:49 +0200 Subject: [PATCH 1/2] using computeIfAbsent to avoid the duplicate registering of Destinations in the MBean Server Signed-off-by: Marc-Olivier Fleury --- .../org/eclipse/jetty/client/HttpClient.java | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java index 82b418f6911..fe57f3241c4 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java @@ -540,24 +540,14 @@ public class HttpClient extends ContainerLifeCycle port = normalizePort(scheme, port); Origin origin = new Origin(scheme, host, port); - HttpDestination destination = destinations.get(origin); - if (destination == null) - { - destination = transport.newHttpDestination(origin); - addManaged(destination); - HttpDestination existing = destinations.putIfAbsent(origin, destination); - if (existing != null) - { - removeBean(destination); - destination = existing; + return destinations.computeIfAbsent(origin, o -> { + HttpDestination newDestination = getTransport().newHttpDestination(o); + addManaged(newDestination); + if (LOG.isDebugEnabled()) { + LOG.debug("Created {}", newDestination); } - else - { - if (LOG.isDebugEnabled()) - LOG.debug("Created {}", destination); - } - } - return destination; + return newDestination; + }); } protected boolean removeDestination(HttpDestination destination) From 8e51a4d5325d6e91c934e5c646f5f392e93aff89 Mon Sep 17 00:00:00 2001 From: Marc-Olivier Fleury Date: Mon, 30 Sep 2019 08:29:39 +0200 Subject: [PATCH 2/2] adjusted formatting to follow standards Signed-off-by: Marc-Olivier Fleury --- .../src/main/java/org/eclipse/jetty/client/HttpClient.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java index fe57f3241c4..fddd0af85bf 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java @@ -540,12 +540,12 @@ public class HttpClient extends ContainerLifeCycle port = normalizePort(scheme, port); Origin origin = new Origin(scheme, host, port); - return destinations.computeIfAbsent(origin, o -> { + return destinations.computeIfAbsent(origin, o -> + { HttpDestination newDestination = getTransport().newHttpDestination(o); addManaged(newDestination); - if (LOG.isDebugEnabled()) { + if (LOG.isDebugEnabled()) LOG.debug("Created {}", newDestination); - } return newDestination; }); }