Example #1
0
 private void DisposeMetricsCollector()
 {
     try
     {
         _metricsCollector.Dispose();
     }
     catch (Exception)
     {
     }
 }
Example #2
0
        /// <summary>
        /// Called by the <see cref="Dispose()"/> method or finalizer to ensure that
        /// resources are released
        /// </summary>
        /// <param name="disposing">Indicates whether this method is called from the
        /// <see cref="Dispose()"/> method (<c>true</c>) or the finalizer (<c>false</c>)</param>
        /// <remarks>
        /// This method will not be called more than once
        /// </remarks>
        protected virtual void Dispose(bool disposing)
        {
            _httpListener.Stop();
            _cancellationTokenSource.Cancel();
            _listenTask.Wait(TimeSpan.FromSeconds(30));
            if (!disposing)
            {
                return;
            }

            _cancellationTokenSource.Dispose();
            try
            {
                _httpListener.Close();

                _diagnosticService.Emit(
                    new HttpEventBuilder(this, HttpEventType.HttpServerStopped)
                {
                    Uri = _baseUri
                }.Build());
            }
            catch (Exception ex)
            {
                _diagnosticService.Emit(
                    new HttpEventBuilder(this, HttpEventType.HttpServerError)
                {
                    Detail    = "Unexpected error closing HTTP listener",
                    Uri       = _baseUri,
                    Exception = ex
                }.Build());
                _httpListener.Abort();
            }

            _bus.Dispose();
            TransportService.Dispose();

            if (_messageQueueingService is IDisposable disposableMessageQueueingService)
            {
                disposableMessageQueueingService.Dispose();
            }

            if (_messageJournal is IDisposable disposableMessageJournal)
            {
                disposableMessageJournal.Dispose();
            }

            if (_subscriptionTrackingService is IDisposable disposableSubscriptionTrackingService)
            {
                disposableSubscriptionTrackingService.Dispose();
            }

            _metricsCollector.Dispose();
        }