// methods private ICluster CreateCluster(ClusterKey clusterKey) { var builder = new ClusterBuilder() .ConfigureCluster(settings => ConfigureCluster(settings, clusterKey)) .ConfigureServer(settings => ConfigureServer(settings, clusterKey)) .ConfigureConnectionPool(settings => ConfigureConnectionPool(settings, clusterKey)) .ConfigureConnection(settings => ConfigureConnection(settings, clusterKey)) .ConfigureTcp(settings => ConfigureTcp(settings, clusterKey)); if (clusterKey.UseSsl) { builder.ConfigureSsl(settings => ConfigureSsl(settings, clusterKey)); } if (clusterKey.ClusterConfigurator != null) { clusterKey.ClusterConfigurator(builder); } var cluster = builder.BuildCluster(); cluster.Initialize(); return(cluster); }
private ConnectionSettings ConfigureConnection(ConnectionSettings settings, ClusterKey clusterKey) { var authenticators = clusterKey.Credentials.Select(c => c.ToAuthenticator()); return(settings.With( authenticators: Optional.Enumerable(authenticators), maxIdleTime: clusterKey.MaxConnectionIdleTime, maxLifeTime: clusterKey.MaxConnectionLifeTime)); }
private TcpStreamSettings ConfigureTcp(TcpStreamSettings settings, ClusterKey clusterKey) { return(settings.With( connectTimeout: clusterKey.ConnectTimeout, readTimeout: clusterKey.SocketTimeout, receiveBufferSize: clusterKey.ReceiveBufferSize, sendBufferSize: clusterKey.SendBufferSize, writeTimeout: clusterKey.SocketTimeout)); }
private ClusterSettings ConfigureCluster(ClusterSettings settings, ClusterKey clusterKey) { var endPoints = clusterKey.Servers.Select(s => (EndPoint) new DnsEndPoint(s.Host, s.Port)); return(settings.With( connectionMode: clusterKey.ConnectionMode.ToCore(), endPoints: Optional.Create(endPoints), replicaSetName: clusterKey.ReplicaSetName, postServerSelector: new LatencyLimitingServerSelector(clusterKey.LocalThreshold))); }
private ConnectionSettings ConfigureConnection(ConnectionSettings settings, ClusterKey clusterKey) { var authenticatorFactories = clusterKey.Credentials.Select(c => new AuthenticatorFactory(() => c.ToAuthenticator())); return(settings.With( authenticatorFactories: Optional.Enumerable <IAuthenticatorFactory>(authenticatorFactories), compressors: Optional.Enumerable(clusterKey.Compressors), maxIdleTime: clusterKey.MaxConnectionIdleTime, maxLifeTime: clusterKey.MaxConnectionLifeTime, applicationName: clusterKey.ApplicationName)); }
private ClusterSettings ConfigureCluster(ClusterSettings settings, ClusterKey clusterKey) { var endPoints = clusterKey.Servers.Select(s => (EndPoint)new DnsEndPoint(s.Host, s.Port)); return settings.With( connectionMode: clusterKey.ConnectionMode.ToCore(), endPoints: Optional.Enumerable(endPoints), replicaSetName: clusterKey.ReplicaSetName, maxServerSelectionWaitQueueSize: clusterKey.WaitQueueSize, serverSelectionTimeout: clusterKey.ServerSelectionTimeout, postServerSelector: new LatencyLimitingServerSelector(clusterKey.LocalThreshold)); }
private ClusterSettings ConfigureCluster(ClusterSettings settings, ClusterKey clusterKey) { var endPoints = clusterKey.Servers.Select(s => EndPointHelper.Parse(s.ToString())); return(settings.With( connectionMode: clusterKey.ConnectionMode.ToCore(), endPoints: Optional.Enumerable(endPoints), replicaSetName: clusterKey.ReplicaSetName, maxServerSelectionWaitQueueSize: clusterKey.WaitQueueSize, serverSelectionTimeout: clusterKey.ServerSelectionTimeout, postServerSelector: new LatencyLimitingServerSelector(clusterKey.LocalThreshold))); }
public ICluster GetOrCreateCluster(ClusterKey clusterKey) { lock (_lock) { ICluster cluster; if (!_registry.TryGetValue(clusterKey, out cluster)) { cluster = CreateCluster(clusterKey); _registry.Add(clusterKey, cluster); } return(cluster); } }
private TcpStreamSettings ConfigureTcp(TcpStreamSettings settings, ClusterKey clusterKey) { if (clusterKey.IPv6) { settings = settings.With(addressFamily: AddressFamily.InterNetworkV6); } return(settings.With( connectTimeout: clusterKey.ConnectTimeout, readTimeout: clusterKey.SocketTimeout, receiveBufferSize: clusterKey.ReceiveBufferSize, sendBufferSize: clusterKey.SendBufferSize, writeTimeout: clusterKey.SocketTimeout)); }
private ClusterSettings ConfigureCluster(ClusterSettings settings, ClusterKey clusterKey) { var endPoints = clusterKey.Servers.Select(s => EndPointHelper.Parse(s.ToString())); return(settings.With( connectionMode: clusterKey.ConnectionMode.ToCore(), endPoints: Optional.Enumerable(endPoints), kmsProviders: Optional.Create(clusterKey.KmsProviders), localThreshold: clusterKey.LocalThreshold, replicaSetName: clusterKey.ReplicaSetName, maxServerSelectionWaitQueueSize: clusterKey.WaitQueueSize, serverSelectionTimeout: clusterKey.ServerSelectionTimeout, schemaMap: Optional.Create(clusterKey.SchemaMap), scheme: clusterKey.Scheme)); }
private SslStreamSettings ConfigureSsl(SslStreamSettings settings, ClusterKey clusterKey) { if (clusterKey.UseSsl) { var sslSettings = clusterKey.SslSettings ?? new SslSettings(); var validationCallback = sslSettings.ServerCertificateValidationCallback; if (validationCallback == null && !clusterKey.VerifySslCertificate) { validationCallback = AcceptAnySslCertificate; } return(settings.With( clientCertificates: Optional.Enumerable(sslSettings.ClientCertificates ?? Enumerable.Empty <X509Certificate>()), checkCertificateRevocation: sslSettings.CheckCertificateRevocation, clientCertificateSelectionCallback: sslSettings.ClientCertificateSelectionCallback, enabledProtocols: sslSettings.EnabledSslProtocols, serverCertificateValidationCallback: validationCallback)); } return(settings); }
private ClusterSettings ConfigureCluster(ClusterSettings settings, ClusterKey clusterKey) { #pragma warning disable CS0618 // Type or member is obsolete var endPoints = clusterKey.Servers.Select(s => EndPointHelper.Parse(s.ToString())); var connectionModeSwitch = clusterKey.ConnectionModeSwitch; Optional <ClusterConnectionMode> connectionMode = connectionModeSwitch == ConnectionModeSwitch.UseConnectionMode ? clusterKey.ConnectionMode.ToCore() : default; Optional <bool?> directConnection = connectionModeSwitch == ConnectionModeSwitch.UseDirectConnection ? clusterKey.DirectConnection : default; return(settings.With( connectionMode: connectionMode, connectionModeSwitch: connectionModeSwitch, directConnection: directConnection, endPoints: Optional.Enumerable(endPoints), kmsProviders: Optional.Create(clusterKey.KmsProviders), localThreshold: clusterKey.LocalThreshold, replicaSetName: clusterKey.ReplicaSetName, maxServerSelectionWaitQueueSize: clusterKey.WaitQueueSize, serverSelectionTimeout: clusterKey.ServerSelectionTimeout, schemaMap: Optional.Create(clusterKey.SchemaMap), scheme: clusterKey.Scheme)); #pragma warning restore CS0618 // Type or member is obsolete }
/// <summary> /// Unregisters and disposes the cluster. /// </summary> /// <param name="cluster">The cluster.</param> public void UnregisterAndDisposeCluster(ICluster cluster) { Ensure.IsNotNull(cluster, nameof(cluster)); lock (_lock) { ClusterKey clusterKey = null; foreach (var keyValuePair in _registry) { if (object.ReferenceEquals(keyValuePair.Value, cluster)) { clusterKey = keyValuePair.Key; break; } } if (clusterKey != null) { _registry.Remove(clusterKey); } } cluster.Dispose(); }
// methods private ICluster CreateCluster(ClusterKey clusterKey) { var builder = new ClusterBuilder() .ConfigureCluster(settings => ConfigureCluster(settings, clusterKey)) .ConfigureServer(settings => ConfigureServer(settings, clusterKey)) .ConfigureConnectionPool(settings => ConfigureConnectionPool(settings, clusterKey)) .ConfigureConnection(settings => ConfigureConnection(settings, clusterKey)) .ConfigureTcp(settings => ConfigureTcp(settings, clusterKey)); if (clusterKey.UseSsl) { builder.ConfigureSsl(settings => ConfigureSsl(settings, clusterKey)); } if (clusterKey.ClusterConfigurator != null) { clusterKey.ClusterConfigurator(builder); } var cluster = builder.BuildCluster(); cluster.Initialize(); return cluster; }
private ConnectionPoolSettings ConfigureConnectionPool(ConnectionPoolSettings settings, ClusterKey clusterKey) { return(settings.With( // maintenanceInterval: TODO: should this be configurable? maxConnections: clusterKey.MaxConnectionPoolSize, minConnections: clusterKey.MinConnectionPoolSize, waitQueueSize: clusterKey.WaitQueueSize, waitQueueTimeout: clusterKey.WaitQueueTimeout)); }
private ConnectionSettings ConfigureConnection(ConnectionSettings settings, ClusterKey clusterKey) { var authenticators = clusterKey.Credentials.Select(c => c.ToAuthenticator()); return settings.With( authenticators: Optional.Enumerable(authenticators), maxIdleTime: clusterKey.MaxConnectionIdleTime, maxLifeTime: clusterKey.MaxConnectionLifeTime, applicationName: clusterKey.ApplicationName); }
private SdamLoggingSettings ConfigureSdamLogging(SdamLoggingSettings settings, ClusterKey clusterKey) { return(settings.With(logFilename: clusterKey.SdamLogFilename)); }
private SslStreamSettings ConfigureSsl(SslStreamSettings settings, ClusterKey clusterKey) { if (clusterKey.UseSsl) { var sslSettings = clusterKey.SslSettings ?? new SslSettings(); var validationCallback = sslSettings.ServerCertificateValidationCallback; if (validationCallback == null && !clusterKey.VerifySslCertificate) { validationCallback = AcceptAnySslCertificate; } return settings.With( clientCertificates: Optional.Enumerable(sslSettings.ClientCertificates ?? Enumerable.Empty<X509Certificate>()), checkCertificateRevocation: sslSettings.CheckCertificateRevocation, clientCertificateSelectionCallback: sslSettings.ClientCertificateSelectionCallback, enabledProtocols: sslSettings.EnabledSslProtocols, serverCertificateValidationCallback: validationCallback); } return settings; }
private ServerSettings ConfigureServer(ServerSettings settings, ClusterKey clusterKey) { return settings.With( heartbeatInterval: clusterKey.HeartbeatInterval, heartbeatTimeout: clusterKey.HeartbeatTimeout); }
private ServerSettings ConfigureServer(ServerSettings settings, ClusterKey clusterKey) { return(settings.With( heartbeatInterval: clusterKey.HeartbeatInterval, heartbeatTimeout: clusterKey.HeartbeatTimeout)); }
private TcpStreamSettings ConfigureTcp(TcpStreamSettings settings, ClusterKey clusterKey) { if (clusterKey.IPv6) { settings = settings.With(addressFamily: AddressFamily.InterNetworkV6); } return settings.With( connectTimeout: clusterKey.ConnectTimeout, readTimeout: clusterKey.SocketTimeout, receiveBufferSize: clusterKey.ReceiveBufferSize, sendBufferSize: clusterKey.SendBufferSize, writeTimeout: clusterKey.SocketTimeout); }
internal ICluster GetOrCreateCluster(ClusterKey clusterKey) { lock (_lock) { ICluster cluster; if (!_registry.TryGetValue(clusterKey, out cluster)) { cluster = CreateCluster(clusterKey); _registry.Add(clusterKey, cluster); } return cluster; } }
private TcpStreamSettings ConfigureTcp(TcpStreamSettings settings, ClusterKey clusterKey) { return settings.With( connectTimeout: clusterKey.ConnectTimeout, readTimeout: clusterKey.SocketTimeout, receiveBufferSize: clusterKey.ReceiveBufferSize, sendBufferSize: clusterKey.SendBufferSize, writeTimeout: clusterKey.SocketTimeout); }
private ConnectionPoolSettings ConfigureConnectionPool(ConnectionPoolSettings settings, ClusterKey clusterKey) { return settings.With( // maintenanceInterval: TODO: should this be configurable? maxConnections: clusterKey.MaxConnectionPoolSize, minConnections: clusterKey.MinConnectionPoolSize, waitQueueSize: clusterKey.WaitQueueSize, waitQueueTimeout: clusterKey.WaitQueueTimeout); }