Skip to content

Commit

Permalink
Gardening: Simplify Node.addService
Browse files Browse the repository at this point in the history
Use Map.computeIfAbsent()

Change-Id: I44b64b682645fadadcc89642c63e939c5691c091
Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/208839
Reviewed-by: Michael Reiche <michael.reiche@couchbase.com>
Tested-by: Build Bot <build@couchbase.com>
  • Loading branch information
dnault committed Apr 19, 2024
1 parent cf75311 commit e8bfe9c
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,8 @@ public synchronized Mono<Void> addService(final ServiceType type, final int port
}

String name = type.scope() == ServiceScope.CLUSTER ? GLOBAL_SCOPE : bucket.orElse(BUCKET_GLOBAL_SCOPE);
Map<ServiceType, Service> localMap = services.get(name);
if (localMap == null) {
localMap = new ConcurrentHashMap<>();
services.put(name, localMap);
}
Map<ServiceType, Service> localMap = services.computeIfAbsent(name, key -> new ConcurrentHashMap<>());

if (!localMap.containsKey(type)) {
long start = System.nanoTime();
Service service = createService(type, port, bucket);
Expand Down

0 comments on commit e8bfe9c

Please sign in to comment.