Search in sources :

Example 1 with OwnedSupplier

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;
}
Also used : OwnedSupplier(com.couchbase.client.core.env.OwnedSupplier) ClusterEnvironment(com.couchbase.client.java.env.ClusterEnvironment) ConnectionStringPropertyLoader(com.couchbase.client.core.env.ConnectionStringPropertyLoader) ConnectionStringUtil.asConnectionString(com.couchbase.client.core.util.ConnectionStringUtil.asConnectionString) ConnectionStringUtil.checkConnectionString(com.couchbase.client.core.util.ConnectionStringUtil.checkConnectionString) ConnectionString(com.couchbase.client.core.util.ConnectionString)

Aggregations

ConnectionStringPropertyLoader (com.couchbase.client.core.env.ConnectionStringPropertyLoader)1 OwnedSupplier (com.couchbase.client.core.env.OwnedSupplier)1 ConnectionString (com.couchbase.client.core.util.ConnectionString)1 ConnectionStringUtil.asConnectionString (com.couchbase.client.core.util.ConnectionStringUtil.asConnectionString)1 ConnectionStringUtil.checkConnectionString (com.couchbase.client.core.util.ConnectionStringUtil.checkConnectionString)1 ClusterEnvironment (com.couchbase.client.java.env.ClusterEnvironment)1