private IStreamFactory CreateStreamFactory(ClusterKey clusterKey)
        {
            // TODO: handle SSL
            var tcpStreamSettings = CreateTcpStreamSettings(clusterKey);

            return(new TcpStreamFactory(tcpStreamSettings));
        }
        // 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);
        }
Beispiel #3
0
 private ConnectionSettings CreateConnectionSettings(ClusterKey clusterKey)
 {
     return(new ConnectionSettings()
            // .WithAuthenticators(_authenticators) // TODO: handle authentication
            .WithMaxIdleTime(clusterKey.MaxConnectionIdleTime)
            .WithMaxLifeTime(clusterKey.MaxConnectionLifeTime));
 }
 private ConnectionSettings CreateConnectionSettings(ClusterKey clusterKey)
 {
     return(new ConnectionSettings()
            .WithAuthenticators(clusterKey.Credentials.Select(c => c.ToAuthenticator()))
            .WithMaxIdleTime(clusterKey.MaxConnectionIdleTime)
            .WithMaxLifeTime(clusterKey.MaxConnectionLifeTime));
 }
 private TcpStreamSettings CreateTcpStreamSettings(ClusterKey clusterKey)
 {
     return(new TcpStreamSettings()
            .WithReadTimeout(clusterKey.SocketTimeout)
            .WithReceiveBufferSize(clusterKey.ReceiveBufferSize)
            .WithSendBufferSize(clusterKey.SendBufferSize)
            .WithWriteTimeout(clusterKey.SocketTimeout));
 }
 private ClusterSettings CreateClusterSettings(ClusterKey clusterKey)
 {
     var endPoints = clusterKey.Servers.Select(s => new DnsEndPoint(s.Host, s.Port));
     return new ClusterSettings()
         .WithConnectionMode(clusterKey.ConnectionMode.ToCore())
         .WithEndPoints(endPoints)
         .WithReplicaSetName(clusterKey.ReplicaSetName);
 }
 private ConnectionPoolSettings CreateConnectionPoolSettings(ClusterKey clusterKey)
 {
     return(new ConnectionPoolSettings()
            // .WithMaintenanceInterval(_connectionPoolMaintenanceInterval) // TODO: is this configurable?
            .WithMaxConnections(clusterKey.MaxConnectionPoolSize)
            .WithMinConnections(clusterKey.MinConnectionPoolSize)
            .WithWaitQueueSize(clusterKey.WaitQueueSize)
            .WithWaitQueueTimeout(clusterKey.WaitQueueTimeout));
 }
        private ClusterSettings CreateClusterSettings(ClusterKey clusterKey)
        {
            var endPoints = clusterKey.Servers.Select(s => new DnsEndPoint(s.Host, s.Port));

            return(new ClusterSettings()
                   .WithConnectionMode(clusterKey.ConnectionMode.ToCore())
                   .WithEndPoints(endPoints)
                   .WithReplicaSetName(clusterKey.ReplicaSetName));
        }
 private ConnectionPoolSettings CreateConnectionPoolSettings(ClusterKey clusterKey)
 {
     return(new ConnectionPoolSettings(
                // maintenanceInterval: TODO: should this be configurable?
                maxConnections: clusterKey.MaxConnectionPoolSize,
                minConnections: clusterKey.MinConnectionPoolSize,
                waitQueueSize: clusterKey.WaitQueueSize,
                waitQueueTimeout: clusterKey.WaitQueueTimeout));
 }
        private ClusterSettings CreateClusterSettings(ClusterKey clusterKey)
        {
            var endPoints = clusterKey.Servers.Select(s => (EndPoint) new DnsEndPoint(s.Host, s.Port));

            return(new ClusterSettings(
                       connectionMode: clusterKey.ConnectionMode.ToCore(),
                       endPoints: Optional.Create(endPoints),
                       replicaSetName: clusterKey.ReplicaSetName));
        }
        private ConnectionSettings CreateConnectionSettings(ClusterKey clusterKey)
        {
            var authenticators = clusterKey.Credentials.Select(c => c.ToAuthenticator());

            return(new ConnectionSettings(
                       authenticators: Optional.Create(authenticators),
                       maxIdleTime: clusterKey.MaxConnectionIdleTime,
                       maxLifeTime: clusterKey.MaxConnectionLifeTime));
        }
 private TcpStreamSettings CreateTcpStreamSettings(ClusterKey clusterKey)
 {
     return(new TcpStreamSettings(
                connectTimeout: clusterKey.ConnectTimeout,
                readTimeout: clusterKey.SocketTimeout,
                receiveBufferSize: clusterKey.ReceiveBufferSize,
                sendBufferSize: clusterKey.SendBufferSize,
                writeTimeout: clusterKey.SocketTimeout));
 }
 private ConnectionPoolSettings CreateConnectionPoolSettings(ClusterKey clusterKey)
 {
     return new ConnectionPoolSettings()
         // .WithMaintenanceInterval(_connectionPoolMaintenanceInterval) // TODO: is this configurable?
         .WithMaxConnections(clusterKey.MaxConnectionPoolSize)
         .WithMinConnections(clusterKey.MinConnectionPoolSize)
         .WithWaitQueueSize(clusterKey.WaitQueueSize)
         .WithWaitQueueTimeout(clusterKey.WaitQueueTimeout);
 }
 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 CreateClusterSettings(ClusterKey clusterKey)
        {
            var endPoints = clusterKey.Servers.Select(s => (EndPoint) new DnsEndPoint(s.Host, s.Port));

            return(new ClusterSettings(
                       connectionMode: clusterKey.ConnectionMode.ToCore(),
                       endPoints: Optional.Create(endPoints),
                       replicaSetName: clusterKey.ReplicaSetName,
                       postServerSelector: new LatencyLimitingServerSelector(clusterKey.LocalThreshold)));
        }
 private ICluster GetOrCreateCluster(ClusterKey clusterKey)
 {
     lock (_lock)
     {
         ICluster cluster;
         if (!_registry.TryGetValue(clusterKey, out cluster))
         {
             cluster = CreateCluster(clusterKey);
             _registry.Add(clusterKey, cluster);
         }
         return(cluster);
     }
 }
        // methods
        private ICluster CreateCluster(ClusterKey clusterKey)
        {
            var clusterSettings = CreateClusterSettings(clusterKey);
            var serverSettings = CreateServerSettings(clusterKey);
            var connectionSettings = CreateConnectionSettings(clusterKey);
            var connectionPoolSettings = CreateConnectionPoolSettings(clusterKey);

            var listener = EmptyListener.Instance;
            var streamFactory = CreateStreamFactory(clusterKey);
            var connectionFactory = new BinaryConnectionFactory(connectionSettings, streamFactory, listener);
            var connectionPoolFactory = new ExclusiveConnectionPoolFactory(connectionPoolSettings, connectionFactory, listener);
            var serverFactory = new ServerFactory(serverSettings, connectionPoolFactory, connectionFactory, listener);
            var clusterFactory = new ClusterFactory(clusterSettings, serverFactory, listener);

            var cluster = clusterFactory.CreateCluster();
            cluster.Initialize();

            return cluster;
        }
        private IStreamFactory CreateStreamFactory(ClusterKey clusterKey)
        {
            var            tcpStreamSettings = CreateTcpStreamSettings(clusterKey);
            IStreamFactory streamFactory     = new TcpStreamFactory(tcpStreamSettings);

            if (clusterKey.SslSettings != null)
            {
                var sslStreamSettings = new SslStreamSettings(
                    new Optional <IEnumerable <X509Certificate> >(clusterKey.SslSettings.ClientCertificates),
                    clusterKey.SslSettings.CheckCertificateRevocation,
                    clusterKey.SslSettings.ClientCertificateSelectionCallback,
                    clusterKey.SslSettings.EnabledSslProtocols,
                    clusterKey.SslSettings.ServerCertificateValidationCallback);

                streamFactory = new SslStreamFactory(sslStreamSettings, streamFactory);
            }

            return(streamFactory);
        }
        private IStreamFactory CreateStreamFactory(ClusterKey clusterKey)
        {
            var            tcpStreamSettings = CreateTcpStreamSettings(clusterKey);
            IStreamFactory streamFactory     = new TcpStreamFactory(tcpStreamSettings);

            if (clusterKey.SslSettings != null)
            {
                var sslStreamSettings = new SslStreamSettings(
                    clientCertificates: Optional.Create(clusterKey.SslSettings.ClientCertificates ?? Enumerable.Empty <X509Certificate>()),
                    checkCertificateRevocation: clusterKey.SslSettings.CheckCertificateRevocation,
                    clientCertificateSelectionCallback: clusterKey.SslSettings.ClientCertificateSelectionCallback,
                    enabledProtocols: clusterKey.SslSettings.EnabledSslProtocols,
                    serverCertificateValidationCallback: clusterKey.SslSettings.ServerCertificateValidationCallback);

                streamFactory = new SslStreamFactory(sslStreamSettings, streamFactory);
            }

            return(streamFactory);
        }
        // methods
        private ICluster CreateCluster(ClusterKey clusterKey)
        {
            var clusterSettings        = CreateClusterSettings(clusterKey);
            var serverSettings         = CreateServerSettings(clusterKey);
            var connectionSettings     = CreateConnectionSettings(clusterKey);
            var connectionPoolSettings = CreateConnectionPoolSettings(clusterKey);

            var listener              = EmptyListener.Instance;
            var streamFactory         = CreateStreamFactory(clusterKey);
            var connectionFactory     = new BinaryConnectionFactory(connectionSettings, streamFactory, listener);
            var connectionPoolFactory = new ExclusiveConnectionPoolFactory(connectionPoolSettings, connectionFactory, listener);
            var serverFactory         = new ServerFactory(serverSettings, connectionPoolFactory, connectionFactory, listener);
            var clusterFactory        = new ClusterFactory(clusterSettings, serverFactory, listener);

            var cluster = clusterFactory.CreateCluster();

            cluster.Initialize();

            return(cluster);
        }
        private SslStreamSettings ConfigureSsl(SslStreamSettings settings, ClusterKey clusterKey)
        {
            if (clusterKey.SslSettings != null)
            {
                var validationCallback = clusterKey.SslSettings.ServerCertificateValidationCallback;
                if (validationCallback == null && !clusterKey.VerifySslCertificate)
                {
                    validationCallback = AcceptAnySslCertificate;
                }

                return(settings.With(
                           clientCertificates: Optional.Create(clusterKey.SslSettings.ClientCertificates ?? Enumerable.Empty <X509Certificate>()),
                           checkCertificateRevocation: clusterKey.SslSettings.CheckCertificateRevocation,
                           clientCertificateSelectionCallback: clusterKey.SslSettings.ClientCertificateSelectionCallback,
                           enabledProtocols: clusterKey.SslSettings.EnabledSslProtocols,
                           serverCertificateValidationCallback: validationCallback));
            }

            return(settings);
        }
 private ServerSettings CreateServerSettings(ClusterKey clusterKey)
 {
     return new ServerSettings()
         .WithHeartbeatInterval(clusterKey.HeartbeatInterval)
         .WithHeartbeatTimeout(clusterKey.HeartbeatTimeout);
 }
 private TcpStreamSettings CreateTcpStreamSettings(ClusterKey clusterKey)
 {
     return new TcpStreamSettings()
         .WithReadTimeout(clusterKey.SocketTimeout)
         .WithReceiveBufferSize(clusterKey.ReceiveBufferSize)
         .WithSendBufferSize(clusterKey.SendBufferSize)
         .WithWriteTimeout(clusterKey.SocketTimeout);
 }
        /// <summary>
        /// Gets an existing cluster or creates a new one.
        /// </summary>
        /// <param name="serverSettings">The server settings.</param>
        /// <returns></returns>
        public ICluster GetOrCreateCluster(MongoServerSettings serverSettings)
        {
            var clusterKey = new ClusterKey(serverSettings);

            return(GetOrCreateCluster(clusterKey));
        }
        /// <summary>
        /// Gets an existing cluster or creates a new one.
        /// </summary>
        /// <param name="clientSettings">The client settings.</param>
        /// <returns></returns>
        public ICluster GetOrCreateCluster(MongoClientSettings clientSettings)
        {
            var clusterKey = new ClusterKey(clientSettings);

            return(GetOrCreateCluster(clusterKey));
        }
 private ICluster GetOrCreateCluster(ClusterKey clusterKey)
 {
     lock (_lock)
     {
         ICluster cluster;
         if (!_registry.TryGetValue(clusterKey, out cluster))
         {
             cluster = CreateCluster(clusterKey);
             _registry.Add(clusterKey, cluster);
         }
         return cluster;
     }
 }
 /// <summary>
 /// Gets an existing cluster or creates a new one.
 /// </summary>
 /// <param name="clientSettings">The client settings.</param>
 /// <returns></returns>
 public ICluster GetOrCreateCluster(MongoClientSettings clientSettings)
 {
     var clusterKey = new ClusterKey(clientSettings);
     return GetOrCreateCluster(clusterKey);
 }
 private ServerSettings CreateServerSettings(ClusterKey clusterKey)
 {
     return(new ServerSettings(
                heartbeatInterval: clusterKey.HeartbeatInterval,
                heartbeatTimeout: clusterKey.HeartbeatTimeout));
 }
 /// <summary>
 /// Gets an existing cluster or creates a new one.
 /// </summary>
 /// <param name="serverSettings">The server settings.</param>
 /// <returns></returns>
 public ICluster GetOrCreateCluster(MongoServerSettings serverSettings)
 {
     var clusterKey = new ClusterKey(serverSettings);
     return GetOrCreateCluster(clusterKey);
 }
 private ServerSettings CreateServerSettings(ClusterKey clusterKey)
 {
     return(new ServerSettings()
            .WithHeartbeatInterval(clusterKey.HeartbeatInterval)
            .WithHeartbeatTimeout(clusterKey.HeartbeatTimeout));
 }
 private IStreamFactory CreateStreamFactory(ClusterKey clusterKey)
 {
     // TODO: handle SSL
     var tcpStreamSettings = CreateTcpStreamSettings(clusterKey);
     return new TcpStreamFactory(tcpStreamSettings);
 }
 private ServerSettings ConfigureServer(ServerSettings settings, ClusterKey clusterKey)
 {
     return(settings.With(
                heartbeatInterval: clusterKey.HeartbeatInterval,
                heartbeatTimeout: clusterKey.HeartbeatTimeout));
 }
 private ConnectionSettings CreateConnectionSettings(ClusterKey clusterKey)
 {
     return new ConnectionSettings()
         // .WithAuthenticators(_authenticators) // TODO: handle authentication
         .WithMaxIdleTime(clusterKey.MaxConnectionIdleTime)
         .WithMaxLifeTime(clusterKey.MaxConnectionLifeTime);
 }