use of com.couchbase.client.core.env.TimeoutConfig.Builder in project connectors-se by Talend.
the class CouchbaseService method openConnection.
public Cluster openConnection(CouchbaseDataStore dataStore) {
String bootStrapNodes = dataStore.getBootstrapNodes();
String username = dataStore.getUsername();
String password = dataStore.getPassword();
String urls = Arrays.stream(resolveAddresses(bootStrapNodes)).collect(Collectors.joining(","));
ClusterHolder holder = clustersPool.computeIfAbsent(dataStore, ds -> {
ClusterEnvironment.Builder envBuilder = ClusterEnvironment.builder();
if (dataStore.isUseConnectionParameters()) {
Builder timeoutBuilder = TimeoutConfig.builder();
dataStore.getConnectionParametersList().forEach(conf -> setTimeout(timeoutBuilder, envBuilder, conf.getParameterName(), parseValue(conf.getParameterValue())));
envBuilder.timeoutConfig(timeoutBuilder);
}
ClusterEnvironment environment = envBuilder.build();
Cluster cluster = Cluster.connect(urls, ClusterOptions.clusterOptions(username, password).environment(environment));
try {
cluster.waitUntilReady(Duration.ofSeconds(3), WaitUntilReadyOptions.waitUntilReadyOptions().desiredState(ClusterState.ONLINE));
} catch (UnambiguousTimeoutException e) {
LOG.error(i18n.connectionKO());
throw new ComponentException(e);
}
return new ClusterHolder(environment, cluster);
});
holder.use();
Cluster cluster = holder.getCluster();
// connection is lazily initialized; need to send actual request to test it
cluster.buckets().getAllBuckets();
PingResult pingResult = cluster.ping();
LOG.debug(i18n.connectedToCluster(pingResult.id()));
return cluster;
}
Aggregations