コード例 #1
0
        public ClusterBuilder AddListener(IListener listener)
        {
            var clusterListener = listener as IClusterListener;

            if (clusterListener != null)
            {
                _clusterListener = ClusterListenerPair.Create(_clusterListener, clusterListener);
            }

            var serverListener = listener as IServerListener;

            if (serverListener != null)
            {
                _serverListener = ServerListenerPair.Create(_serverListener, serverListener);
            }

            var connectionPoolListener = listener as IConnectionPoolListener;

            if (connectionPoolListener != null)
            {
                _connectionPoolListener = ConnectionPoolListenerPair.Create(_connectionPoolListener, connectionPoolListener);
            }

            var connectionListener = listener as IConnectionListener;

            if (connectionListener != null)
            {
                _connectionListener = ConnectionListenerPair.Create(_connectionListener, connectionListener);
            }

            return(this);
        }
コード例 #2
0
        // static
        public static IConnectionPoolListener Create(IConnectionPoolListener first, IConnectionPoolListener second)
        {
            if (first == null)
            {
                return(second);
            }

            if (second == null)
            {
                return(first);
            }

            return(new ConnectionPoolListenerPair(first, second));
        }
コード例 #3
0
        // static
        public static IConnectionPoolListener Create(IConnectionPoolListener first, IConnectionPoolListener second)
        {
            if (first == null)
            {
                return second;
            }

            if (second == null)
            {
                return first;
            }

            return new ConnectionPoolListenerPair(first, second);
        }
コード例 #4
0
        // constructors
        public ExclusiveConnectionPool(
            ServerId serverId,
            EndPoint endPoint,
            ConnectionPoolSettings settings,
            IConnectionFactory connectionFactory,
            IConnectionPoolListener listener)
        {
            _serverId = Ensure.IsNotNull(serverId, "serverId");
            _endPoint = Ensure.IsNotNull(endPoint, "endPoint");
            _settings = Ensure.IsNotNull(settings, "settings");
            _connectionFactory = Ensure.IsNotNull(connectionFactory, "connectionFactory");
            _listener = listener;

            _connectionHolder = new ListConnectionHolder(_listener);
            _poolQueue = new WaitQueue(settings.MaxConnections);
            _waitQueue = new SemaphoreSlim(settings.WaitQueueSize);
            _maintenanceCancellationTokenSource = new CancellationTokenSource();
            _state = new InterlockedInt32(State.Initial);
        }
コード例 #5
0
        // constructors
        public ExclusiveConnectionPool(
            ServerId serverId,
            EndPoint endPoint,
            ConnectionPoolSettings settings,
            IConnectionFactory connectionFactory,
            IConnectionPoolListener listener)
        {
            _serverId          = Ensure.IsNotNull(serverId, "serverId");
            _endPoint          = Ensure.IsNotNull(endPoint, "endPoint");
            _settings          = Ensure.IsNotNull(settings, "settings");
            _connectionFactory = Ensure.IsNotNull(connectionFactory, "connectionFactory");
            _listener          = listener;

            _connectionHolder = new ListConnectionHolder(_listener);
            _poolQueue        = new WaitQueue(settings.MaxConnections);
            _waitQueue        = new SemaphoreSlim(settings.WaitQueueSize);
            _maintenanceCancellationTokenSource = new CancellationTokenSource();
            _state = new InterlockedInt32(State.Initial);
        }
コード例 #6
0
        public void Setup()
        {
            _connectionFactory = Substitute.For <IConnectionFactory>();
            _endPoint          = new DnsEndPoint("localhost", 27017);
            _listener          = Substitute.For <IConnectionPoolListener>();
            _serverId          = new ServerId(new ClusterId(), _endPoint);
            _settings          = new ConnectionPoolSettings()
                                 .WithMaintenanceInterval(Timeout.InfiniteTimeSpan)
                                 .WithMaxConnections(4)
                                 .WithMinConnections(2)
                                 .WithWaitQueueSize(1);

            _subject = new ExclusiveConnectionPool(
                _serverId,
                _endPoint,
                _settings,
                _connectionFactory,
                _listener);
        }
コード例 #7
0
        public void Setup()
        {
            _connectionFactory = Substitute.For <IConnectionFactory>();
            _endPoint          = new DnsEndPoint("localhost", 27017);
            _listener          = Substitute.For <IConnectionPoolListener>();
            _serverId          = new ServerId(new ClusterId(), _endPoint);
            _settings          = new ConnectionPoolSettings(
                maintenanceInterval: Timeout.InfiniteTimeSpan,
                maxConnections: 4,
                minConnections: 2,
                waitQueueSize: 1,
                waitQueueTimeout: TimeSpan.FromSeconds(2));

            _subject = new ExclusiveConnectionPool(
                _serverId,
                _endPoint,
                _settings,
                _connectionFactory,
                _listener);
        }
コード例 #8
0
 public ExclusiveConnectionPoolFactory(ConnectionPoolSettings settings, IConnectionFactory connectionFactory, IConnectionPoolListener listener)
 {
     _settings          = Ensure.IsNotNull(settings, "settings");
     _connectionFactory = Ensure.IsNotNull(connectionFactory, "connectionFactory");
     _listener          = listener;
 }
コード例 #9
0
 public ListConnectionHolder(IConnectionPoolListener listener)
 {
     _listener = listener;
     _connections = new List<PooledConnection>();
 }
コード例 #10
0
 public ListConnectionHolder(IConnectionPoolListener listener)
 {
     _listener    = listener;
     _connections = new List <PooledConnection>();
 }
コード例 #11
0
 // constructors
 public ConnectionPoolListenerPair(IConnectionPoolListener first, IConnectionPoolListener second)
 {
     _first  = Ensure.IsNotNull(first, "first");
     _second = Ensure.IsNotNull(second, "second");
 }
コード例 #12
0
        public void Setup()
        {
            _connectionFactory = Substitute.For<IConnectionFactory>();
            _endPoint = new DnsEndPoint("localhost", 27017);
            _listener = Substitute.For<IConnectionPoolListener>();
            _serverId = new ServerId(new ClusterId(), _endPoint);
            _settings = new ConnectionPoolSettings()
                .WithMaintenanceInterval(Timeout.InfiniteTimeSpan)
                .WithMaxConnections(4)
                .WithMinConnections(2)
                .WithWaitQueueSize(1);

            _subject = new ExclusiveConnectionPool(
                _serverId,
                _endPoint,
                _settings,
                _connectionFactory,
                _listener);
        }
コード例 #13
0
 public ExclusiveConnectionPoolFactory(ConnectionPoolSettings settings, IConnectionFactory connectionFactory, IConnectionPoolListener listener)
 {
     _settings = Ensure.IsNotNull(settings, "settings");
     _connectionFactory = Ensure.IsNotNull(connectionFactory, "connectionFactory");
     _listener = listener;
 }
コード例 #14
0
 // constructors
 public ConnectionPoolListenerPair(IConnectionPoolListener first, IConnectionPoolListener second)
 {
     _first = Ensure.IsNotNull(first, "first");
     _second = Ensure.IsNotNull(second, "second");
 }
コード例 #15
0
        public ClusterBuilder AddListener(IListener listener)
        {
            var clusterListener = listener as IClusterListener;
            if (clusterListener != null)
            {
                _clusterListener = ClusterListenerPair.Create(_clusterListener, clusterListener);
            }

            var serverListener = listener as IServerListener;
            if (serverListener != null)
            {
                _serverListener = ServerListenerPair.Create(_serverListener, serverListener);
            }

            var connectionPoolListener = listener as IConnectionPoolListener;
            if (connectionPoolListener != null)
            {
                _connectionPoolListener = ConnectionPoolListenerPair.Create(_connectionPoolListener, connectionPoolListener);
            }

            var connectionListener = listener as IConnectionListener;
            if (connectionListener != null)
            {
                _connectionListener = ConnectionListenerPair.Create(_connectionListener, connectionListener);
            }

            return this;
        }