コード例 #1
0
        /// <summary>
        /// 将当前缓冲内的完整数据放入分发队列并重置缓冲
        /// </summary>
        public static void FlushBuffer()
        {
            var currIndex = CycleInfo.GetCurrentIndex();
            if (currIndex > cycle.Index)
            {
                AggregateBlock prevBuffer = null;
                if (Monitor.TryEnter(cycle))
                {
                    if (currIndex > cycle.Index)
                    {
                        //重置当前缓冲
                        prevBuffer = buffer;
                        buffer = new AggregateBlock(CycleInfo.GetStartTime(currIndex));

                        //设置当前周期
                        cycle.Index = currIndex;
                    }

                    Monitor.Exit(cycle);
                }

                //将前一个缓冲数据放入分发队列
                if (prevBuffer != null)
                    queue.Enqueue(prevBuffer);
            }
        }
コード例 #2
0
        public void AggregateBlock_Data_Test()
        {
            Thread.GetDomain().SetData(".appPath", AppDomain.CurrentDomain.BaseDirectory);
            Thread.GetDomain().SetData(".appVPath", "/");
            Thread.GetDomain().SetData(".appDomain", "*");

            AggregateBlock aggregateBlock = new AggregateBlock(DateTime.Now);
            System.Collections.Generic.Dictionary<string, string> tag = new System.Collections.Generic.Dictionary<string, string>();
            tag.Add("url", "localhost");
            AggregateKey key = new AggregateKey("", "count", tag, AggregateType.Count);
            aggregateBlock.PutDouble(key, 10.10);

            AggregateKey key1 = new AggregateKey("", "Histogram", tag, AggregateType.Histogram);
            aggregateBlock.PutDouble(key1, 10.10);

            Assert.AreEqual(aggregateBlock.Data.Count, 2);
        }