Skip to content

Commit

Permalink
Gardening: Simplify Core.reconfigureGlobal/Buckets
Browse files Browse the repository at this point in the history
Change-Id: Id57678df182d32a27dfef90d76cfb3f550637153
Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/208833
Reviewed-by: David Nault <david.nault@couchbase.com>
Tested-by: Build Bot <build@couchbase.com>
  • Loading branch information
dnault committed Apr 18, 2024
1 parent ddaed24 commit 426c995
Showing 1 changed file with 14 additions and 29 deletions.
43 changes: 14 additions & 29 deletions core-io/src/main/java/com/couchbase/client/core/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@

import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -810,32 +809,25 @@ private Mono<Void> reconfigureGlobal(final GlobalConfig config) {
.flatMap(ni -> {
boolean tls = coreContext.environment().securityConfig().tlsEnabled();

Set<Map.Entry<ServiceType, Integer>> aServices = null;
Map<ServiceType, Integer> aServices = null;
Optional<String> alternateAddress = coreContext.alternateAddress();
String aHost = null;
if (alternateAddress.isPresent()) {
AlternateAddress aa = ni.alternateAddresses().get(alternateAddress.get());
aHost = aa.hostname();
aServices = tls ? aa.sslServices().entrySet() : aa.services().entrySet();
aServices = tls ? aa.sslServices() : aa.services();
}

if (aServices == null || aServices.isEmpty()) {
aServices = tls ? ni.sslPorts().entrySet() : ni.ports().entrySet();
aServices = tls ? ni.sslPorts() : ni.ports();
}

final String alternateHost = aHost;
final Set<Map.Entry<ServiceType, Integer>> services = aServices;
final Map<ServiceType, Integer> services = aServices;

Flux<Void> serviceRemoveFlux = Flux
.fromIterable(Arrays.asList(ServiceType.values()))
.filter(s -> {
for (Map.Entry<ServiceType, Integer> inConfig : services) {
if (inConfig.getKey() == s) {
return false;
}
}
return true;
})
.fromArray(ServiceType.values())
.filter(s -> !services.containsKey(s))
.flatMap(s -> removeServiceFrom(
ni.identifier(),
s,
Expand All @@ -853,7 +845,7 @@ private Mono<Void> reconfigureGlobal(final GlobalConfig config) {


Flux<Void> serviceAddFlux = Flux
.fromIterable(services)
.fromIterable(services.entrySet())
.flatMap(s -> ensureServiceAt(
ni.identifier(),
s.getKey(),
Expand Down Expand Up @@ -889,33 +881,26 @@ private Mono<Void> reconfigureBuckets(final Flux<BucketConfig> bucketConfigs) {
.flatMap(ni -> {
boolean tls = coreContext.environment().securityConfig().tlsEnabled();

Set<Map.Entry<ServiceType, Integer>> aServices = null;
Map<ServiceType, Integer> aServices = null;
Optional<String> alternateAddress = coreContext.alternateAddress();
String aHost = null;
if (alternateAddress.isPresent()) {
AlternateAddress aa = ni.alternateAddresses().get(alternateAddress.get());
aHost = aa.hostname();
aServices = tls ? aa.sslServices().entrySet() : aa.services().entrySet();
aServices = tls ? aa.sslServices() : aa.services();
}


if (isNullOrEmpty(aServices)) {
aServices = tls ? ni.sslServices().entrySet() : ni.services().entrySet();
aServices = tls ? ni.sslServices() : ni.services();
}

final String alternateHost = aHost;
final Set<Map.Entry<ServiceType, Integer>> services = aServices;
final Map<ServiceType, Integer> services = aServices;

Flux<Void> serviceRemoveFlux = Flux
.fromIterable(Arrays.asList(ServiceType.values()))
.filter(s -> {
for (Map.Entry<ServiceType, Integer> inConfig : services) {
if (inConfig.getKey() == s) {
return false;
}
}
return true;
})
.fromArray(ServiceType.values())
.filter(s -> !services.containsKey(s))
.flatMap(s -> removeServiceFrom(
ni.identifier(),
s,
Expand All @@ -932,7 +917,7 @@ private Mono<Void> reconfigureBuckets(final Flux<BucketConfig> bucketConfigs) {
);

Flux<Void> serviceAddFlux = Flux
.fromIterable(services)
.fromIterable(services.entrySet())
.flatMap(s -> ensureServiceAt(
ni.identifier(),
s.getKey(),
Expand Down

0 comments on commit 426c995

Please sign in to comment.