Beispiel #1
0
 public void ReturnToPool(ICounterItem item)
 {
     if (item is CounterItem <T> value)
     {
         foreach (var lVal in value.Values)
         {
             CounterItemValue <T> .Store(lVal);
         }
         CounterItem <T> .Store(value);
     }
 }
Beispiel #2
0
        ICounterItem ICounterReader.Take(int items)
        {
            if (_counterValues.Count == 0)
            {
                return(null);
            }
            var lstItems = new List <CounterItemValue <T> >();
            var itemIdx  = 0;

            while (itemIdx < items && _counterValues.TryTake(out var item))
            {
                if (item == _lastValue)
                {
                    lock (_valueLock)
                    {
                        _lastValue = null;
                    }
                }
                lstItems.Add(item);
                itemIdx++;
            }
            return(CounterItem <T> .Retrieve(Category, Name, Type, Level, Kind, Unit, lstItems));
        }
Beispiel #3
0
        public void Add(T value)
        {
            //Now with a truncate to 5 seconds
            var now       = Core.Now.TruncateTo(TimeSpan.FromSeconds(5));
            var lastValue = _lastValue;

            if (lastValue?.Timestamp == now)
            {
                var nValue = MergeValues(lastValue.Value, value);
                lock (_valueLock)
                {
                    if (_lastValue != null)
                    {
                        _lastValue.Value = nValue;
                        return;
                    }
                }
            }
            var newItem = CounterItemValue <T> .Retrieve(now, value);

            _lastValue = newItem;
            _counterValues.Add(newItem);
        }
Beispiel #4
0
 public static void Store(CounterItemValue <T> item)
 {
     item.Timestamp = DateTime.MinValue;
     item.Value     = default;
     ReferencePool <CounterItemValue <T> > .Shared.Store(item);
 }