use of com.couchbase.client.core.env.OwnedSupplier in project couchbase-jvm-clients by couchbase.
the class AsyncCluster method extractClusterEnvironment.
/**
* Helper method to extract the cluster environment from the connection string and options.
*
* @param connectionString the connection string which is used to populate settings into it.
* @param opts the cluster options.
* @return the cluster environment, created if not passed in or the one supplied from the user.
*/
static Supplier<ClusterEnvironment> extractClusterEnvironment(final String connectionString, final ClusterOptions.Built opts) {
ConnectionString connStr = ConnectionString.create(connectionString);
Supplier<ClusterEnvironment> envSupplier;
if (opts.environment() == null) {
ClusterEnvironment.Builder builder = ClusterEnvironment.builder();
if (opts.environmentCustomizer() != null) {
opts.environmentCustomizer().accept(builder);
}
builder.load(new ConnectionStringPropertyLoader(connStr));
envSupplier = new OwnedSupplier<>(builder.build());
} else {
envSupplier = opts::environment;
}
boolean ownsEnvironment = envSupplier instanceof OwnedSupplier;
checkConnectionString(envSupplier.get(), ownsEnvironment, connStr);
return envSupplier;
}
Aggregations