예제 #1
0
        // 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);
        }
예제 #2
0
        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));
        }
예제 #3
0
 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));
 }
예제 #4
0
        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));
 }
예제 #7
0
        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)));
        }
예제 #8
0
 public ICluster GetOrCreateCluster(ClusterKey clusterKey)
 {
     lock (_lock)
     {
         ICluster cluster;
         if (!_registry.TryGetValue(clusterKey, out cluster))
         {
             cluster = CreateCluster(clusterKey);
             _registry.Add(clusterKey, cluster);
         }
         return(cluster);
     }
 }
예제 #9
0
        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));
        }
예제 #11
0
        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;
        }
예제 #15
0
 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);
 }
예제 #20
0
 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;
     }
 }
예제 #23
0
 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);
 }