/// <summary>
 ///     Closes the reporter for this tracer.
 /// </summary>
 public void Close()
 {
     reporter.Close();
     sdkMetricsRegistry?.Dispose();
     metricsScheduler?.Dispose();
     heartbeaterService?.Dispose();
 }
        /// <summary>
        /// Disposes the current instance and resources associated with it
        /// </summary>
        /// <param name="disposing">Value indicating whether the managed resources should also be disposed</param>
        protected virtual void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }

            _connection.ConnectionShutdown    -= OnConnectionShutdown;
            _feedRecoveryManager.ProducerDown -= MarkProducerAsDown;
            _feedRecoveryManager.ProducerUp   -= MarkProducerAsUp;
            _feedRecoveryManager.CloseFeed    -= OnCloseFeed;
            _feedRecoveryManager.Close();

            _metricsTaskScheduler.Dispose();

            foreach (var session in Sessions)
            {
                session.Close();
            }

            if (disposing)
            {
                try
                {
                    UnityContainer.Dispose();
                }
                catch (Exception ex)
                {
                    _log.LogWarning("An exception has occurred while disposing the feed instance. Exception: ", ex);
                }
            }

            _isDisposed = true;
        }
Example #3
0
        /// <summary>
        /// Disposes the current instance and resources associated with it
        /// </summary>
        /// <param name="disposing">Value indicating whether the managed resources should also be disposed</param>
        protected virtual void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }

            _rabbitMqMessageReceiverForTickets.MqMessageReceived -= OnMqMessageReceived;
            //_rabbitMqMessageReceiverForTickets.MqMessageDeserializationFailed -= OnMqMessageDeserializationFailed;
            _rabbitMqMessageReceiverForTickets.Close();

            _rabbitMqMessageReceiverForTicketCancels.MqMessageReceived -= OnMqMessageReceived;
            //_rabbitMqMessageReceiverForTicketCancels.MqMessageDeserializationFailed -= OnMqMessageDeserializationFailed;
            _rabbitMqMessageReceiverForTicketCancels.Close();

            _rabbitMqMessageReceiverForTicketCashouts.MqMessageReceived -= OnMqMessageReceived;
            //_rabbitMqMessageReceiverForTicketCashouts.MqMessageDeserializationFailed -= OnMqMessageDeserializationFailed;
            _rabbitMqMessageReceiverForTicketCashouts.Close();

            _rabbitMqMessageReceiverForTicketNonSrSettle.MqMessageReceived -= OnMqMessageReceived;
            //_rabbitMqMessageReceiverForTicketNonSrSettle.MqMessageDeserializationFailed -= OnMqMessageDeserializationFailed;
            _rabbitMqMessageReceiverForTicketNonSrSettle.Close();

            _ticketPublisherFactory.Close();

            _metricsTaskScheduler.Dispose();

            foreach (var item in _autoResetEventsForBlockingRequests)
            {
                _autoResetEventsForBlockingRequests.TryRemove(item.Key, out var arEvent);
                _executionLog.LogDebug($"Disposing AutoResetEvent for TicketId: {item.Key}.");
                arEvent.Dispose();
            }

            _responsesFromBlockingRequests.Clear();

            if (disposing)
            {
                try
                {
                    _unityContainer.Dispose();
                }
                catch (Exception ex)
                {
                    _executionLog.LogWarning("An exception has occurred while disposing the feed instance. Exception: ", ex);
                }
            }

            _isDisposed = true;
            _isOpened   = 0;
        }
Example #4
0
        /// <summary>
        /// Disposes the current instance and resources associated with it
        /// </summary>
        /// <param name="disposing">Value indicating whether the managed resources should also be disposed</param>
        protected virtual void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }

            if (_connectionFactory != null)
            {
                DetachFromConnectionEvents();
            }

            if (_feedRecoveryManager != null)
            {
                _feedRecoveryManager.ProducerDown           -= MarkProducerAsDown;
                _feedRecoveryManager.ProducerUp             -= MarkProducerAsUp;
                _feedRecoveryManager.CloseFeed              -= OnCloseFeed;
                _feedRecoveryManager.EventRecoveryCompleted -= OnEventRecoveryCompleted;
                _feedRecoveryManager.Close();
            }

            _metricsTaskScheduler?.Dispose();

            foreach (var session in Sessions)
            {
                session.Close();
            }

            EventChangeManager.Stop();

            if (disposing)
            {
                try
                {
                    UnityContainer.Dispose();
                }
                catch (Exception ex)
                {
                    _log.LogWarning(ex, "An exception has occurred while disposing the feed instance. Exception: ");
                }
            }

            _isDisposed = true;
        }
        private static async Task Main()
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Information()
                         .WriteTo.Console()
                         .WriteTo.Seq("http://localhost:5341/")
                         .CreateLogger();

            Log.Information("Starting AppMetrics Serilog Reporter sample");

            var metrics = AppMetrics.CreateDefaultBuilder()
                          .Configuration.Configure(options =>
                                                   options.GlobalTags.Add("InstanceId", Guid.NewGuid().ToString("N")))
                          .Report.ToConsole()
                          .Report.ToSerilog(LogEventLevel.Information)
                          .Build();

            var cts = new CancellationTokenSource();

            var scheduler = new AppMetricsTaskScheduler(
                TimeSpan.FromSeconds(3),
                () => Task.WhenAll(metrics.ReportRunner.RunAllAsync()));

            scheduler.Start();

            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                eventArgs.Cancel = true;
                scheduler.Dispose();
                cts.Cancel();
            };

            var counterTask   = RunCounter(metrics, cts.Token);
            var timerTask     = RunTimer(metrics, cts.Token);
            var meterTask     = RunMeter(metrics, cts.Token);
            var histogramTask = RunHistogram(metrics, cts.Token);
            var gaugeTask     = RunGauge(metrics, cts.Token);

            await Task.WhenAll(counterTask, timerTask, meterTask, histogramTask, gaugeTask);

            Log.Information("Sample application shutdown");
            Log.CloseAndFlush();
        }
 public void Dispose()
 {
     _scheduler.Dispose();
 }
 /// <inheritdoc />
 public void Dispose()
 {
     _scheduler?.Dispose();
     _logger?.LogInformation($"Stopped {nameof(MetricsReporterService)}");
 }
Example #8
0
 public static async Task FlushReporter()
 {
     _scheduler?.Dispose();
     await Task.WhenAll(_metrics.ReportRunner.RunAllAsync()).ConfigureAwait(false);
 }