Beispiel #1
0
        private void TimerCallback(object state)
        {
            if (Interlocked.CompareExchange(ref _processing, 1, 0) == 1)
            {
                return;
            }
            try
            {
                if (_traceItems.Count == 0)
                {
                    Interlocked.Exchange(ref _processing, 0);
                    return;
                }

                var itemsToSend = _pool.New();
                while (itemsToSend.Count < 2048 && _traceItems.TryTake(out var item, 10))
                {
                    itemsToSend.Add(item);
                    Interlocked.Decrement(ref _count);
                }

                Core.Log.LibDebug("Sending {0} trace items to the diagnostic queue.", itemsToSend.Count);
                if (_queueClient is null)
                {
                    _queueClient = Core.Services.GetQueueRawClient(_queueName, true);
                    Core.Status.AttachChild(_queueClient, this);
                }
                _queueClient.SendAsync(itemsToSend).WaitAndResults();

                itemsToSend.Clear();
                _pool.Store(itemsToSend);
            }
            catch (UriFormatException fException)
            {
                Core.Log.Warning($"Disabling {nameof(MessagingTraceStorage)}. Reason: {fException.Message}");
                _enabled = false;
                _timer.Dispose();
            }
            catch (Exception ex)
            {
                Core.Log.Write(ex);
            }
            Interlocked.Exchange(ref _processing, 0);
        }
Beispiel #2
0
 private void TimerCallback(object state)
 {
     if (!_enabled)
     {
         return;
     }
     if (Interlocked.CompareExchange(ref _processing, 1, 0) == 1)
     {
         return;
     }
     try
     {
         var statusData = OnFetchStatus?.Invoke();
         if (statusData is null)
         {
             Interlocked.Exchange(ref _processing, 0);
             return;
         }
         Core.Log.LibDebug("Sending status data to the diagnostic queue.");
         if (_queueClient is null)
         {
             _queueClient = Core.Services.GetQueueRawClient(_queueName, true);
             Core.Status.AttachChild(_queueClient, this);
         }
         _queueClient.SendAsync(statusData).WaitAndResults();
     }
     catch (UriFormatException fException)
     {
         Core.Log.Warning($"Disabling {nameof(MessagingStatusTransport)}. Reason: {fException.Message}");
         _enabled = false;
         _timer.Dispose();
     }
     catch (Exception ex)
     {
         Core.Log.Write(ex);
     }
     Interlocked.Exchange(ref _processing, 0);
 }
Beispiel #3
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     _queueClient?.Dispose();
     _queueClient = null;
     GC.SuppressFinalize(this);
 }
Beispiel #4
0
 /// <summary>
 /// Messaging log storage
 /// </summary>
 /// <param name="queueClient">Queue client</param>
 public MessagingCountersStorage(IMQueueRawClient queueClient)
 {
     _queueClient = queueClient;
 }
Beispiel #5
0
 /// <summary>
 /// Messaging log storage
 /// </summary>
 /// <param name="queueName">Queue pair config name</param>
 public MessagingCountersStorage(string queueName)
 {
     _queueClient = Core.Services.GetQueueRawClient(queueName, true);
 }
Beispiel #6
0
        private void TimerCallback(object state)
        {
            if (Interlocked.CompareExchange(ref _processing, 1, 0) == 1)
            {
                return;
            }
            try
            {
                if (_items.Count == 0)
                {
                    Interlocked.Exchange(ref _processing, 0);
                    return;
                }

                var logItemsToSend = _pool.New();
                var metadataToSend = _poolGroup.New();
                while (logItemsToSend.Count < 2048 && metadataToSend.Count < 2048 && _items.TryTake(out var item, 10))
                {
                    if (item is LogItem lItem)
                    {
                        logItemsToSend.Add(lItem);
                    }
                    else if (item is GroupMetadata gItem)
                    {
                        metadataToSend.Add(gItem);
                    }
                    Interlocked.Decrement(ref _count);
                }

                Core.Log.LibDebug("Sending {0} log items to the diagnostic queue.", logItemsToSend.Count + metadataToSend.Count);
                if (_queueClient is null)
                {
                    _queueClient = Core.Services.GetQueueRawClient(_queueName, true);
                    Core.Status.AttachChild(_queueClient, this);
                }

                var tskLogs  = logItemsToSend.Count > 0 ? _queueClient.SendAsync(logItemsToSend) : Task.CompletedTask;
                var tskGroup = metadataToSend.Count > 0 ? _queueClient.SendAsync(metadataToSend) : Task.CompletedTask;

                _tsks[0] = tskLogs;
                _tsks[1] = tskGroup;
                Task.WaitAll(_tsks);
                _tsks[0] = null;
                _tsks[1] = null;

                logItemsToSend.Clear();
                metadataToSend.Clear();
                _pool.Store(logItemsToSend);
                _poolGroup.Store(metadataToSend);
            }
            catch (UriFormatException fException)
            {
                Core.Log.Warning($"Disabling {nameof(MessagingLogStorage)}. Reason: {fException.Message}");
                _enabled = false;
                _timer.Dispose();
            }
            catch
            {
                //
            }
            Interlocked.Exchange(ref _processing, 0);
        }