Esempio n. 1
0
        /// <inheritdoc/>
        public async Task StopAsync(CancellationToken cancellationToken)
        {
            _stopTokenSource?.Cancel();

            await StopPluginsAsync(_sources.Values.Where(s => s != _metrics), cancellationToken);

            await StopPluginsAsync(_sinks.Values, cancellationToken);

            await StopPluginsAsync(_plugins, cancellationToken);

            await _bookmarkManager.StopAsync(cancellationToken);

            _sinks.Clear();
            _networkStatus.ResetNetworkStatusProviders();
            _logger.LogInformation("Stopped");
        }
        public void Stop()
        {
            _configTimer.Change(Timeout.Infinite, Timeout.Infinite);
            _updateTimer.Change(Timeout.Infinite, Timeout.Infinite);

            foreach (ISource source in _sources.Values)
            {
                try
                {
                    source.Stop();
                    IDisposable disposableSource = source as IDisposable;
                    disposableSource?.Dispose();
                }
                catch (Exception ex)
                {
                    _logger?.LogError($"Error stopping source {source.Id}: {ex.ToMinimized()}");
                }
            }
            _sources.Clear();

            foreach (var subscription in _subscriptions)
            {
                try
                {
                    subscription?.Dispose();
                }
                catch (Exception ex)
                {
                    _logger?.LogError($"Error stopping subscription: {ex.ToMinimized()}");
                }
            }
            _subscriptions.Clear();

            foreach (ISink sink in _sinks.Values)
            {
                try
                {
                    sink.Stop();
                }
                catch (Exception ex)
                {
                    _logger?.LogError($"Error stopping sink {sink.Id}: {ex.ToMinimized()}");
                }
            }
            _sinks.Clear();

            foreach (var plugin in _plugins)
            {
                try
                {
                    plugin.Stop();
                }
                catch (Exception ex)
                {
                    _logger?.LogError($"Error stopping plugin {plugin.GetType()}: {ex.ToMinimized()}");
                }
            }

            NetworkStatus.ResetNetworkStatusProviders();
            _logger?.LogInformation("Log manager stopped.");
        }
Esempio n. 3
0
        public void Stop(bool serviceStopping)
        {
            _configTimer.Change(Timeout.Infinite, Timeout.Infinite);
            _updateTimer.Change(Timeout.Infinite, Timeout.Infinite);

            var sourceStopTasks = new List <Task>();

            foreach (ISource source in _sources.Values)
            {
                sourceStopTasks.Add(Task.Run(() =>
                {
                    try
                    {
                        source.Stop();
                        if (source is IDisposable disposableSource)
                        {
                            disposableSource.Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"Error stopping source {source.Id}: {ex.ToMinimized()}");
                    }
                }));
            }

            if (!serviceStopping)
            {
                // Wait for items to stop, then move on if even if they haven't within the time limit.
                if (Task.WaitAll(sourceStopTasks.ToArray(), TimeSpan.FromSeconds(300)))
                {
                    _logger.LogDebug("All sources stopped gracefully.");
                }
                _sources.Clear();
            }

            var subscriptionStopTasks = new List <Task>();

            foreach (var subscription in _subscriptions)
            {
                subscriptionStopTasks.Add(Task.Run(() =>
                {
                    try
                    {
                        subscription?.Dispose();
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"Error stopping subscription: {ex.ToMinimized()}");
                    }
                }));
            }

            if (!serviceStopping)
            {
                // Wait for items to stop, then move on if even if they haven't within the time limit.
                if (Task.WaitAll(subscriptionStopTasks.ToArray(), TimeSpan.FromSeconds(300)))
                {
                    _logger.LogDebug("All subscriptions stopped gracefully.");
                }
                _subscriptions.Clear();
            }

            // Since the sinks need a longer time to flush, we'll stop all the plugins at the same time.
            var sinksAndPluginStopTasks = new List <Task>();

            foreach (ISink sink in _sinks.Values)
            {
                sinksAndPluginStopTasks.Add(Task.Run(() =>
                {
                    try
                    {
                        sink.Stop();
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"Error stopping sink {sink.Id}: {ex.ToMinimized()}");
                    }
                }));
            }

            foreach (var plugin in _plugins)
            {
                sinksAndPluginStopTasks.Add(Task.Run(() =>
                {
                    try
                    {
                        plugin.Stop();
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"Error stopping plugin {plugin.GetType()}: {ex.ToMinimized()}");
                    }
                }));
            }

            // If the sinks don't flush in time, the class that invoked the Stop method
            // will be logging an event, so we don't need to do so here. We want to give them
            // as long as possible to shut down, so we'll set a super high value, which will cover
            // the use case of both a timeLimited and a non-timeLimited Stop operation.
            if (Task.WaitAll(sinksAndPluginStopTasks.ToArray(), TimeSpan.FromSeconds(600)))
            {
                _logger.LogDebug("All sinks stopped gracefully.");
            }
            _sinks.Clear();

            NetworkStatus.ResetNetworkStatusProviders();
            _logger.LogInformation("Log manager stopped.");
        }
Esempio n. 4
0
        public void Stop(bool serviceStopping)
        {
            var sourceStopTasks = new List <Task>();

            foreach (ISource source in _sources.Values)
            {
                sourceStopTasks.Add(Task.Run(() =>
                {
                    try
                    {
                        source.Stop();
                        if (!serviceStopping && source is IDisposable i)
                        {
                            i.Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"Error stopping source {source.Id}: {ex.ToMinimized()}");
                    }
                }));
            }

            if (!serviceStopping)
            {
                // Wait for items to stop, then move on if even if they haven't within the time limit.
                if (Task.WaitAll(sourceStopTasks.ToArray(), TimeSpan.FromSeconds(300)))
                {
                    _logger.LogDebug("All sources stopped gracefully.");
                }
                _sources.Clear();
            }

            // Since the sinks need a longer time to flush, we'll stop all the plugins at the same time.
            var sinksAndPluginStopTasks = new List <Task>();

            foreach (ISink sink in _sinks.Values)
            {
                sinksAndPluginStopTasks.Add(Task.Run(() =>
                {
                    try
                    {
                        sink.Stop();
                        if (!serviceStopping && sink is IDisposable i)
                        {
                            i.Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"Error stopping sink {sink.Id}: {ex.ToMinimized()}");
                    }
                }));
            }

            foreach (var plugin in _plugins)
            {
                sinksAndPluginStopTasks.Add(Task.Run(() =>
                {
                    try
                    {
                        plugin.Stop();
                        if (!serviceStopping && plugin is IDisposable i)
                        {
                            i.Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"Error stopping plugin {plugin.GetType()}: {ex.ToMinimized()}");
                    }
                }));
            }

            // If the sinks don't flush in time, the class that invoked the Stop method
            // will be logging an event, so we don't need to do so here. We want to give them
            // as long as possible to shut down, so we'll set a super high value, which will cover
            // the use case of both a timeLimited and a non-timeLimited Stop operation.
            if (Task.WaitAll(sinksAndPluginStopTasks.ToArray(), TimeSpan.FromSeconds(600)))
            {
                _logger.LogDebug("All sinks stopped gracefully.");
            }

            // cancel the background task that might still be restarting sinks and pipes
            _restartSinksAndPipesCts.Cancel();
            // wait for the background task to finish
            _restartSinksAndPipesTask.GetAwaiter().GetResult();

            _sinks.Clear();

            // Clean all sinks and pipes that need to restart in order to terminate background task
            _sinksToRestart.Clear();
            _pipesToRestart.Clear();

            _networkStatus.ResetNetworkStatusProviders();
            _logger.LogInformation("Stopped.");
        }