Esempio n. 1
0
        // constructors
        public ExclusiveConnectionPool(
            ServerId serverId,
            EndPoint endPoint,
            ConnectionPoolSettings settings,
            IConnectionFactory connectionFactory,
            IEventSubscriber eventSubscriber)
        {
            _serverId          = Ensure.IsNotNull(serverId, nameof(serverId));
            _endPoint          = Ensure.IsNotNull(endPoint, nameof(endPoint));
            _settings          = Ensure.IsNotNull(settings, nameof(settings));
            _connectionFactory = Ensure.IsNotNull(connectionFactory, nameof(connectionFactory));
            Ensure.IsNotNull(eventSubscriber, nameof(eventSubscriber));

            _connectionHolder = new ListConnectionHolder(eventSubscriber);
            _poolQueue        = new WaitQueue(settings.MaxConnections);
            _waitQueue        = new SemaphoreSlim(settings.WaitQueueSize);
            _maintenanceCancellationTokenSource = new CancellationTokenSource();
            _state = new InterlockedInt32(State.Initial);

            eventSubscriber.TryGetEventHandler(out _checkingOutConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _checkedOutConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _checkingOutConnectionFailedEventHandler);
            eventSubscriber.TryGetEventHandler(out _checkingInConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _checkedInConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _addingConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _addedConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _openingEventHandler);
            eventSubscriber.TryGetEventHandler(out _openedEventHandler);
            eventSubscriber.TryGetEventHandler(out _closingEventHandler);
            eventSubscriber.TryGetEventHandler(out _closedEventHandler);
            eventSubscriber.TryGetEventHandler(out _addingConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _addedConnectionEventHandler);
        }
Esempio n. 2
0
        // constructors
        public ExclusiveConnectionPool(
            ServerId serverId,
            EndPoint endPoint,
            ConnectionPoolSettings settings,
            IConnectionFactory connectionFactory,
            IEventSubscriber eventSubscriber,
            IConnectionExceptionHandler connectionExceptionHandler)
        {
            _serverId                   = Ensure.IsNotNull(serverId, nameof(serverId));
            _endPoint                   = Ensure.IsNotNull(endPoint, nameof(endPoint));
            _settings                   = Ensure.IsNotNull(settings, nameof(settings));
            _connectionFactory          = Ensure.IsNotNull(connectionFactory, nameof(connectionFactory));
            _connectionExceptionHandler = Ensure.IsNotNull(connectionExceptionHandler, nameof(connectionExceptionHandler));
            Ensure.IsNotNull(eventSubscriber, nameof(eventSubscriber));

            _maintenanceHelper     = new MaintenanceHelper(MaintainSize, _settings.MaintenanceInterval);
            _poolState             = new PoolState(EndPointHelper.ToString(_endPoint));
            _checkOutReasonCounter = new CheckOutReasonCounter();

            _maxConnectingQueue  = new SemaphoreSlimSignalable(settings.MaxConnecting);
            _connectionHolder    = new ListConnectionHolder(eventSubscriber, _maxConnectingQueue);
            _maxConnectionsQueue = new SemaphoreSlimSignalable(settings.MaxConnections);

            _serviceStates = new ServiceStates();
#pragma warning disable 618
            _waitQueueFreeSlots = settings.WaitQueueSize;
#pragma warning restore 618

            eventSubscriber.TryGetEventHandler(out _checkingOutConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _checkedOutConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _checkingOutConnectionFailedEventHandler);
            eventSubscriber.TryGetEventHandler(out _checkingInConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _checkedInConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _addingConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _addedConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _openingEventHandler);
            eventSubscriber.TryGetEventHandler(out _openedEventHandler);
            eventSubscriber.TryGetEventHandler(out _closingEventHandler);
            eventSubscriber.TryGetEventHandler(out _closedEventHandler);
            eventSubscriber.TryGetEventHandler(out _readyEventHandler);
            eventSubscriber.TryGetEventHandler(out _addingConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _addedConnectionEventHandler);
            eventSubscriber.TryGetEventHandler(out _clearingEventHandler);
            eventSubscriber.TryGetEventHandler(out _clearedEventHandler);
            eventSubscriber.TryGetEventHandler(out _connectionCreatedEventHandler);
        }
Esempio n. 3
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);
        }