public async Task <ICluster> GetClusterAsync() { if (cluster is null == false) { return(cluster); } Builder builder = initializer as Builder; if (builder is null) { builder = DataStax.Cluster.Builder(); // TODO: check inside the `cfg` (var cfg = builder.GetConfiguration();) if we already have connectionString specified string connectionString = options.ConnectionString; var hackyBuilder = new CassandraConnectionStringBuilder(connectionString); if (string.IsNullOrEmpty(hackyBuilder.DefaultKeyspace) == false) { connectionString = connectionString.Replace(hackyBuilder.DefaultKeyspace, string.Empty); } baseConfigurationKeyspace = hackyBuilder.DefaultKeyspace; var connStrBuilder = new CassandraConnectionStringBuilder(connectionString); cluster?.Shutdown(30000); cluster = connStrBuilder .ApplyToBuilder(builder) .WithReconnectionPolicy(new ExponentialReconnectionPolicy(100, 100000)) .WithRetryPolicy(new NoHintedHandOffRetryPolicy()) .Build(); await cluster.RefreshSchemaAsync().ConfigureAwait(false); } else { cluster = DataStax.Cluster.BuildFrom(initializer); } return(cluster); }
public Cluster GetCluster() { if (cluster is null == false && optionsHasChanged == false) { return(cluster); } Builder builder = initializer as Builder; if (builder is null) { builder = Cluster.Builder(); // TODO: check inside the `cfg` (var cfg = builder.GetConfiguration();) if we already have connectionString specified string connectionString = options.ConnectionString; var hackyBuilder = new CassandraConnectionStringBuilder(connectionString); if (string.IsNullOrEmpty(hackyBuilder.DefaultKeyspace) == false) { connectionString = connectionString.Replace(hackyBuilder.DefaultKeyspace, string.Empty); } baseConfigurationKeyspace = hackyBuilder.DefaultKeyspace; var connStrBuilder = new CassandraConnectionStringBuilder(connectionString); cluster = connStrBuilder .ApplyToBuilder(builder) .WithReconnectionPolicy(new ExponentialReconnectionPolicy(100, 100000)) .WithRetryPolicy(new NoHintedHandOffRetryPolicy()) .Build(); } else { cluster = Cluster.BuildFrom(initializer); } optionsHasChanged = false; return(cluster); }
/// <summary> /// Configure the cluster by applying settings from ConnectionString. /// </summary> /// <param name="connectionString"> the ConnectionString to use </param> /// /// <returns>this Builder</returns> public Builder WithConnectionString(string connectionString) { var cnb = new CassandraConnectionStringBuilder(connectionString); return cnb.ApplyToBuilder(this); }