use of com.couchbase.client.core.cnc.EventBus in project couchbase-elasticsearch-connector by couchbase.
the class SeedNodeHelper method getKvNodes.
/**
* Returns complete host and port information for every node running the KV service.
*/
public static Set<SeedNode> getKvNodes(Bucket bucket, String connectionString, boolean tls, NetworkResolution networkResolution, Duration timeout) {
// Bucket config is most reliable way to determine KV ports
BucketConfig config = CouchbaseHelper.getConfig(bucket, timeout);
// so the actual node names can be used.
if (networkResolution.equals(NetworkResolution.AUTO)) {
EventBus eventBus = bucket.environment().eventBus();
// The Java client calls seedNodesFromConnectionString during bootstrap, but the results
// are not accessible here. Call it again.
Set<String> seedHosts = ConnectionStringUtil.seedNodesFromConnectionString(connectionString, true, tls, eventBus).stream().map(SeedNode::address).collect(toSet());
networkResolution = inferNetwork(config, networkResolution, seedHosts);
}
// Resolve alternate addresses
// so lambda can access it
NetworkResolution finalNetworkResolution = networkResolution;
return config.nodes().stream().map(node -> new ResolvedNodeInfo(node, tls, finalNetworkResolution)).map(node -> SeedNode.create(node.host(), node.port(KV), node.port(MANAGER))).filter(node -> node.kvPort().isPresent()).collect(toSet());
}
use of com.couchbase.client.core.cnc.EventBus in project kafka-connect-couchbase by couchbase.
the class SeedNodeHelper method getKvNodes.
/**
* Returns complete host and port information for every node running the KV service.
*/
public static Set<SeedNode> getKvNodes(Bucket bucket, String connectionString, boolean tls, NetworkResolution networkResolution, Duration timeout) {
// Bucket config is most reliable way to determine KV ports
BucketConfig config = CouchbaseHelper.getConfig(bucket, timeout);
// so the actual node names can be used.
if (networkResolution.equals(NetworkResolution.AUTO)) {
EventBus eventBus = bucket.environment().eventBus();
// The Java client calls seedNodesFromConnectionString during bootstrap, but the results
// are not accessible here. Call it again.
Set<String> seedHosts = ConnectionStringUtil.seedNodesFromConnectionString(connectionString, true, tls, eventBus).stream().map(SeedNode::address).collect(toSet());
networkResolution = inferNetwork(config, networkResolution, seedHosts);
}
// Resolve alternate addresses
// so lambda can access it
NetworkResolution finalNetworkResolution = networkResolution;
return config.nodes().stream().map(node -> new ResolvedNodeInfo(node, tls, finalNetworkResolution)).map(node -> SeedNode.create(node.host(), node.port(KV), node.port(MANAGER))).filter(node -> node.kvPort().isPresent()).collect(toSet());
}
use of com.couchbase.client.core.cnc.EventBus in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProvider method loadAndRefreshGlobalConfig.
@Override
public Mono<Void> loadAndRefreshGlobalConfig() {
return Mono.defer(() -> {
if (!shutdown.get()) {
globalConfigLoadInProgress = true;
boolean tls = core.context().environment().securityConfig().tlsEnabled();
int kvPort = tls ? DEFAULT_KV_TLS_PORT : DEFAULT_KV_PORT;
final AtomicBoolean hasErrored = new AtomicBoolean();
return Flux.range(1, Math.min(MAX_PARALLEL_LOADERS, currentSeedNodes().size())).flatMap(index -> Flux.fromIterable(currentSeedNodes()).take(Math.min(index, currentSeedNodes().size())).last().flatMap(seed -> {
long start = System.nanoTime();
if (!currentSeedNodes().contains(seed)) {
// node we are about to load is still part of the list.
return Mono.empty();
}
NodeIdentifier identifier = new NodeIdentifier(seed.address(), seed.clusterManagerPort().orElse(DEFAULT_MANAGER_PORT));
return globalLoader.load(identifier, seed.kvPort().orElse(kvPort)).doOnError(throwable -> core.context().environment().eventBus().publish(new IndividualGlobalConfigLoadFailedEvent(Duration.ofNanos(System.nanoTime() - start), core.context(), throwable, seed.address())));
}).retryWhen(Retry.from(companion -> companion.flatMap(rs -> {
Throwable f = rs.failure();
if (shutdown.get()) {
return Mono.error(new AlreadyShutdownException());
}
if (f instanceof UnsupportedConfigMechanismException) {
return Mono.error(Exceptions.propagate(f));
}
Duration delay = Duration.ofMillis(1);
eventBus.publish(new GlobalConfigRetriedEvent(delay, core.context(), f));
return Mono.just(rs.totalRetries()).delayElement(delay, core.context().environment().scheduler());
}))).onErrorResume(throwable -> {
if (hasErrored.compareAndSet(false, true)) {
return Mono.error(throwable);
}
return Mono.empty();
})).take(1).switchIfEmpty(Mono.error(new ConfigException("Could not locate a single global configuration"))).map(ctx -> {
proposeGlobalConfig(ctx);
return ctx;
}).then(globalRefresher.start()).doOnTerminate(() -> globalConfigLoadInProgress = false);
} else {
return Mono.error(new AlreadyShutdownException());
}
});
}
use of com.couchbase.client.core.cnc.EventBus in project couchbase-jvm-clients by couchbase.
the class MemcacheProtocolTest method before.
@BeforeEach
void before() {
eventBus = mock(EventBus.class);
CoreEnvironment env = mock(CoreEnvironment.class);
context = new CoreContext(mock(Core.class), 1, env, mock(Authenticator.class));
when(env.eventBus()).thenReturn(eventBus);
}
Aggregations