using computeIfAbsent to avoid the duplicate registering of Destinations in the MBean Server

Signed-off-by: Marc-Olivier Fleury <mofleury@gmail.com>
This commit is contained in:
Marc-Olivier Fleury 2019-09-20 14:26:49 +02:00 committed by Marc-Olivier Fleury
parent 69d52b2263
commit ebe28c27e4
1 changed files with 7 additions and 17 deletions

View File

@ -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)