コード例 #1
0
        public virtual void TestCopy()
        {
            AbstractMetricsContext.TagMap tags = new AbstractMetricsContext.TagMap();
            tags["tagkey"] = "tagval";
            AbstractMetricsContext.MetricMap metrics = new AbstractMetricsContext.MetricMap();
            metrics["metrickey"] = 123.4;
            OutputRecord r = new OutputRecord(tags, metrics);

            Assert.Equal(tags, r.GetTagsCopy());
            NUnit.Framework.Assert.AreNotSame(tags, r.GetTagsCopy());
            Assert.Equal(metrics, r.GetMetricsCopy());
            NUnit.Framework.Assert.AreNotSame(metrics, r.GetMetricsCopy());
        }
コード例 #2
0
 /// <summary>Returns true if this tagmap contains every tag in other.</summary>
 public virtual bool ContainsAll(AbstractMetricsContext.TagMap other)
 {
     foreach (KeyValuePair <string, object> entry in other)
     {
         object value = this[entry.Key];
         if (value == null || !value.Equals(entry.Value))
         {
             // either key does not exist here, or the value is different
             return(false);
         }
     }
     return(true);
 }
コード例 #3
0
        /// <summary>Called by MetricsRecordImpl.remove().</summary>
        /// <remarks>
        /// Called by MetricsRecordImpl.remove().  Removes all matching rows in
        /// the internal table of metric data.  A row matches if it has the same
        /// tag names and values as record, but it may also have additional
        /// tags.
        /// </remarks>
        protected internal virtual void Remove(MetricsRecordImpl record)
        {
            string recordName = record.GetRecordName();

            AbstractMetricsContext.TagMap    tagTable  = record.GetTagTable();
            AbstractMetricsContext.RecordMap recordMap = GetRecordMap(recordName);
            lock (recordMap)
            {
                IEnumerator <AbstractMetricsContext.TagMap> it = recordMap.Keys.GetEnumerator();
                while (it.HasNext())
                {
                    AbstractMetricsContext.TagMap rowTags = it.Next();
                    if (rowTags.ContainsAll(tagTable))
                    {
                        it.Remove();
                    }
                }
            }
        }
コード例 #4
0
        /// <summary>Called by MetricsRecordImpl.update().</summary>
        /// <remarks>
        /// Called by MetricsRecordImpl.update().  Creates or updates a row in
        /// the internal table of metric data.
        /// </remarks>
        protected internal virtual void Update(MetricsRecordImpl record)
        {
            string recordName = record.GetRecordName();

            AbstractMetricsContext.TagMap     tagTable      = record.GetTagTable();
            IDictionary <string, MetricValue> metricUpdates = record.GetMetricTable();

            AbstractMetricsContext.RecordMap recordMap = GetRecordMap(recordName);
            lock (recordMap)
            {
                AbstractMetricsContext.MetricMap metricMap = recordMap[tagTable];
                if (metricMap == null)
                {
                    metricMap = new AbstractMetricsContext.MetricMap();
                    AbstractMetricsContext.TagMap tagMap = new AbstractMetricsContext.TagMap(tagTable
                                                                                             );
                    // clone tags
                    recordMap[tagMap] = metricMap;
                }
                ICollection <KeyValuePair <string, MetricValue> > entrySet = metricUpdates;
                foreach (KeyValuePair <string, MetricValue> entry in entrySet)
                {
                    string      metricName    = entry.Key;
                    MetricValue updateValue   = entry.Value;
                    Number      updateNumber  = updateValue.GetNumber();
                    Number      currentNumber = metricMap[metricName];
                    if (currentNumber == null || updateValue.IsAbsolute())
                    {
                        metricMap[metricName] = updateNumber;
                    }
                    else
                    {
                        Number newNumber = Sum(updateNumber, currentNumber);
                        metricMap[metricName] = newNumber;
                    }
                }
            }
        }
コード例 #5
0
 /// <summary>Creates a new instance of OutputRecord</summary>
 internal OutputRecord(AbstractMetricsContext.TagMap tagMap, AbstractMetricsContext.MetricMap
                       metricMap)
 {
     this.tagMap    = tagMap;
     this.metricMap = metricMap;
 }
コード例 #6
0
 internal TagMap(AbstractMetricsContext.TagMap orig)
     : base(orig)
 {
 }