Ejemplo n.º 1
0
 private void RequestInstancesAndNoFree(IPool <Bar> pool, int count)
 {
     for (int i = 0; i < count; i++)
     {
         var ins = pool.New();
     }
 }
Ejemplo n.º 2
0
        private void TimerCallback(object state)
        {
            if (_processing)
            {
                return;
            }
            _processing = true;
            try
            {
                if (_logItems.Count == 0)
                {
                    _processing = false;
                    return;
                }

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

                Core.Log.LibDebug("Sending {0} log items to the diagnostic queue.", itemsToSend.Count);
                _queueClient = _queueClient ?? Core.Services.GetQueueClient(_queueName);
                _queueClient.SendAsync(itemsToSend).WaitAndResults();

                itemsToSend.Clear();
                _pool.Store(itemsToSend);
            }
            catch
            {
                //
            }
            _processing = false;
        }
Ejemplo n.º 3
0
        private void RequestInstancesAndFree(IPool <Bar> pool, int count)
        {
            Bar[] instances = new Bar[count];

            for (int i = 0; i < count; i++)
            {
                instances[i] = pool.New();
            }

            foreach (var bizthing in instances)
            {
                pool.Free(bizthing);
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
 public static object[] New(int length)
 {
     return(current.New(length));
 }
Ejemplo n.º 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);
        }