Skip to content

Commit

Permalink
Gardening: Simplify Node.addService
Browse files Browse the repository at this point in the history
Invert the "service already added?" condition
so the bail-out code comes first.

Change-Id: Ife5cb9e8efbb33ea6fc62c43fe4d005ca0ea1940
Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/208842
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Michael Reiche <michael.reiche@couchbase.com>
  • Loading branch information
dnault committed Apr 19, 2024
1 parent bff68d1 commit 441adc1
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions core-io/src/main/java/com/couchbase/client/core/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,25 +236,25 @@ 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.computeIfAbsent(name, key -> new ConcurrentHashMap<>());

if (!localMap.containsKey(type)) {
NanoTimestamp start = NanoTimestamp.now();
Service service = createService(type, port, bucket);
serviceStates.register(service, service);
localMap.put(type, service);
enabledServices.set(enabledServices.get() | 1 << type.ordinal());
// todo: only return once the service is connected?
service.connect();
ctx.environment().eventBus().publish(
new ServiceAddedEvent(start.elapsed(), service.context())
);
if (localMap.containsKey(type)) {
ctx.environment().eventBus().publish(new ServiceAddIgnoredEvent(
Event.Severity.VERBOSE,
ServiceAddIgnoredEvent.Reason.ALREADY_ADDED,
ctx
));
return;
}

ctx.environment().eventBus().publish(new ServiceAddIgnoredEvent(
Event.Severity.VERBOSE,
ServiceAddIgnoredEvent.Reason.ALREADY_ADDED,
ctx
));
NanoTimestamp start = NanoTimestamp.now();
Service service = createService(type, port, bucket);
serviceStates.register(service, service);
localMap.put(type, service);
enabledServices.set(enabledServices.get() | 1 << type.ordinal());
// todo: only return once the service is connected?
service.connect();
ctx.environment().eventBus().publish(
new ServiceAddedEvent(start.elapsed(), service.context())
);
});
}

Expand Down

0 comments on commit 441adc1

Please sign in to comment.