Example #1
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.");
        }
Example #2
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);
        }
        /// <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;
        }