use of com.couchbase.client.core.cnc.events.config.SeedNodesUpdatedEvent in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProvider method updateSeedNodeList.
/**
* Helper method to take the current config and update the seed node list with the latest topology.
*
* <p>If we have a global config it is used for simplicity reasons. Otherwise we iterate the configs and collect
* all the nodes to build the list.</p>
*/
private void updateSeedNodeList() {
ClusterConfig config = currentConfig;
boolean tlsEnabled = core.context().environment().securityConfig().tlsEnabled();
if (config.globalConfig() != null) {
Set<SeedNode> seedNodes = unmodifiableSet(config.globalConfig().portInfos().stream().map(ni -> {
Map<ServiceType, Integer> ports = tlsEnabled ? ni.sslPorts() : ni.ports();
if (!ports.containsKey(ServiceType.KV)) {
// We only want seed nodes where the KV service is enabled
return null;
}
return SeedNode.create(ni.hostname(), Optional.ofNullable(ports.get(ServiceType.KV)), Optional.ofNullable(ports.get(ServiceType.MANAGER)));
}).filter(Objects::nonNull).collect(Collectors.toSet()));
if (!seedNodes.isEmpty()) {
eventBus.publish(new SeedNodesUpdatedEvent(core.context(), currentSeedNodes(), seedNodes));
setSeedNodes(seedNodes);
}
return;
}
Set<SeedNode> seedNodes = unmodifiableSet(config.bucketConfigs().values().stream().flatMap(bc -> bc.nodes().stream()).map(ni -> {
Map<ServiceType, Integer> ports = tlsEnabled ? ni.sslServices() : ni.services();
if (!ports.containsKey(ServiceType.KV)) {
// We only want seed nodes where the KV service is enabled
return null;
}
return SeedNode.create(ni.hostname(), Optional.ofNullable(ports.get(ServiceType.KV)), Optional.ofNullable(ports.get(ServiceType.MANAGER)));
}).filter(Objects::nonNull).collect(Collectors.toSet()));
if (!seedNodes.isEmpty()) {
eventBus.publish(new SeedNodesUpdatedEvent(core.context(), currentSeedNodes(), seedNodes));
setSeedNodes(seedNodes);
}
}
Aggregations