示例#1
0
        /// <summary>
        /// Releases the resources associated with the pool.
        /// </summary>
        public void Dispose()
        {
            var markShuttingDown =
                (Interlocked.CompareExchange(ref _state, PoolState.ShuttingDown, PoolState.Init) == PoolState.Init) ||
                (Interlocked.CompareExchange(ref _state, PoolState.ShuttingDown, PoolState.Closing) ==
                 PoolState.Closing);

            if (!markShuttingDown)
            {
                // The pool is already being shutdown, never mind
                return;
            }
            Logger.Info("Disposing connection pool #{0} to {1}", GetHashCode(), _host.Address);
            var connections = _connections.ClearAndGet();

            foreach (var c in connections)
            {
                c.Dispose();
            }
            _host.Up              -= OnHostUp;
            _host.Down            -= OnHostDown;
            _host.Remove          -= OnHostRemoved;
            _host.DistanceChanged -= OnDistanceChanged;
            var t = _resizingEndTimeout;

            if (t != null)
            {
                t.Cancel();
            }
            CancelNewConnectionTimeout();
            Interlocked.Exchange(ref _state, PoolState.Shutdown);
        }
示例#2
0
        /// <inheritdoc />
        public async Task ShutdownAsync(int timeoutMs = Timeout.Infinite)
        {
            if (!_initialized)
            {
                return;
            }
            var sessions = _connectedSessions.ClearAndGet();

            try
            {
                var task = Task.Run(() =>
                {
                    foreach (var s in sessions)
                    {
                        s.Dispose();
                    }
                }).WaitToCompleteAsync(timeoutMs);
                await task.ConfigureAwait(false);
            }
            catch (AggregateException ex)
            {
                if (ex.InnerExceptions.Count == 1)
                {
                    throw ex.InnerExceptions[0];
                }
                throw;
            }
            _metadata.ShutDown(timeoutMs);
            _controlConnection.Dispose();
            Configuration.Timer.Dispose();
            Configuration.Policies.SpeculativeExecutionPolicy.Dispose();
            _logger.Info("Cluster [" + _metadata.ClusterName + "] has been shut down.");
        }
示例#3
0
        public void Shutdown()
        {
            _isShuttingDown = true;
            var connections = _connections.ClearAndGet();

            if (connections.Length == 0)
            {
                return;
            }
            Logger.Info(string.Format("Shutting down pool to {0}, closing {1} connection(s).", _host.Address, connections.Length));
            foreach (var c in connections)
            {
                c.Dispose();
            }
        }
示例#4
0
        /// <inheritdoc />
        async Task <bool> IInternalCluster.OnShutdownAsync(int timeoutMs)
        {
            if (!_initialized)
            {
                return(false);
            }
            var sessions = _connectedSessions.ClearAndGet();

            try
            {
                var task = Task.Run(() =>
                {
                    foreach (var s in sessions)
                    {
                        s.Dispose();
                    }
                }).WaitToCompleteAsync(timeoutMs);
                await task.ConfigureAwait(false);
            }
            catch (AggregateException ex)
            {
                if (ex.InnerExceptions.Count == 1)
                {
                    throw ex.InnerExceptions[0];
                }
                throw;
            }
            _metadata.ShutDown(timeoutMs);
            _protocolEventDebouncer.Dispose();
            _controlConnection.Dispose();
            Configuration.Timer.Dispose();

            // Dispose policies
            var speculativeExecutionPolicies = new HashSet <ISpeculativeExecutionPolicy>(new ReferenceEqualityComparer <ISpeculativeExecutionPolicy>());

            foreach (var options in Configuration.RequestOptions.Values)
            {
                speculativeExecutionPolicies.Add(options.SpeculativeExecutionPolicy);
            }

            speculativeExecutionPolicies.Add(Configuration.Policies.SpeculativeExecutionPolicy);
            foreach (var sep in speculativeExecutionPolicies)
            {
                sep.Dispose();
            }

            return(true);
        }
示例#5
0
        /// <inheritdoc />
        public async Task ShutdownAsync(int timeoutMs = Timeout.Infinite)
        {
            if (!_initialized)
            {
                return;
            }
            var sessions = _connectedSessions.ClearAndGet();

            try
            {
                var tasks = new List <Task>();
                foreach (var s in sessions)
                {
                    tasks.Add(s.ShutdownAsync());
                }

                await Task.WhenAll(tasks).WaitToCompleteAsync(timeoutMs).ConfigureAwait(false);
            }
            catch (AggregateException ex)
            {
                if (ex.InnerExceptions.Count == 1)
                {
                    throw ex.InnerExceptions[0];
                }
                throw;
            }
            _metadata.ShutDown(timeoutMs);
            _controlConnection.Dispose();
            await _protocolEventDebouncer.ShutdownAsync().ConfigureAwait(false);

            Configuration.Timer.Dispose();

            // Dispose policies
            var speculativeExecutionPolicies = new HashSet <ISpeculativeExecutionPolicy>(new ReferenceEqualityComparer <ISpeculativeExecutionPolicy>());

            foreach (var options in Configuration.RequestOptions.Values)
            {
                speculativeExecutionPolicies.Add(options.SpeculativeExecutionPolicy);
            }

            foreach (var sep in speculativeExecutionPolicies)
            {
                sep.Dispose();
            }

            Cluster.Logger.Info("Cluster [" + Metadata.ClusterName + "] has been shut down.");
            return;
        }