Skip to content

Commit

Permalink
Gardening: Simplify Node.addService
Browse files Browse the repository at this point in the history
Use Mono.fromRunnable() instead of Mono.defer()

Change-Id: Ia6775c5004371c4f6b7226e283105e7334a89228
Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/208837
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 426c995 commit cf75311
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 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 @@ -222,14 +222,14 @@ public synchronized Mono<Void> disconnect() {
*/
public synchronized Mono<Void> addService(final ServiceType type, final int port,
final Optional<String> bucket) {
return Mono.defer(() -> {
return Mono.fromRunnable(() -> {
if (disconnect.get()) {
ctx.environment().eventBus().publish(new ServiceAddIgnoredEvent(
Event.Severity.DEBUG,
ServiceAddIgnoredEvent.Reason.DISCONNECTED,
ctx
));
return Mono.empty();
return;
}

String name = type.scope() == ServiceScope.CLUSTER ? GLOBAL_SCOPE : bucket.orElse(BUCKET_GLOBAL_SCOPE);
Expand All @@ -250,15 +250,14 @@ public synchronized Mono<Void> addService(final ServiceType type, final int port
ctx.environment().eventBus().publish(
new ServiceAddedEvent(Duration.ofNanos(end - start), service.context())
);
return Mono.empty();
} else {
ctx.environment().eventBus().publish(new ServiceAddIgnoredEvent(
Event.Severity.VERBOSE,
ServiceAddIgnoredEvent.Reason.ALREADY_ADDED,
ctx
));
return Mono.empty();
return;
}

ctx.environment().eventBus().publish(new ServiceAddIgnoredEvent(
Event.Severity.VERBOSE,
ServiceAddIgnoredEvent.Reason.ALREADY_ADDED,
ctx
));
});
}

Expand Down

0 comments on commit cf75311

Please sign in to comment.