Beispiel #1
0
 internal static void ValidateSlidingWindowAndBucketLength(TimeSpan slidingWindowLength, TimeSpan bucketLength)
 {
     ExAssert.RetailAssert(bucketLength >= SlidingWindow.MinBucketLength, "bucketLength: [{0}] must be at least [{1}].", new object[]
     {
         bucketLength,
         SlidingWindow.MinBucketLength
     });
     ExAssert.RetailAssert(slidingWindowLength > TimeSpan.Zero, "slidingWindowLength: [{0}] must be greater than zero.", new object[]
     {
         slidingWindowLength
     });
     ExAssert.RetailAssert(bucketLength < slidingWindowLength, "bucketLength: [{0}] must be less than slidingWindowLength: [{1}]", new object[]
     {
         bucketLength,
         slidingWindowLength
     });
     ExAssert.RetailAssert(slidingWindowLength <= SlidingWindow.MaxSlidingWindowLength, "slidingWindowLength: [{0}] must be less than or equal to slidingWindowLength: [{1}]", new object[]
     {
         slidingWindowLength,
         SlidingWindow.MaxSlidingWindowLength
     });
     ExAssert.RetailAssert(slidingWindowLength.Ticks % bucketLength.Ticks == 0L, "slidingWindowLength: [{0}] must be a multiple of bucketLength: [{1}]", new object[]
     {
         slidingWindowLength,
         bucketLength
     });
 }
Beispiel #2
0
        protected void ExpireBucketsIfNecessary()
        {
            ExAssert.RetailAssert(this.ValueBuckets != null, "Child class did not create a ValueBuckets array");
            if (this.ValueBuckets.Length != this.NumberOfBuckets)
            {
                ExAssert.RetailAssert(false, "The child class did not define the appropriate number of elements in the ValueBuckets array. Expected: {0}, Actual: {1}", new object[]
                {
                    this.NumberOfBuckets,
                    this.ValueBuckets.Length
                });
            }
            DateTime d    = this.currentTimeProvider();
            long     num  = (d - this.creationTime).Ticks / this.BucketLength.Ticks;
            int      num2 = 0;

            while (num2 < this.ValueBuckets.Length && this.totalBucketsExpired < num)
            {
                this.currentBucket = (this.currentBucket + 1) % this.ValueBuckets.Length;
                this.ExpireBucket(this.currentBucket);
                this.filled[this.currentBucket] = false;
                this.totalBucketsExpired       += 1L;
                num2++;
            }
            this.totalBucketsExpired = num;
        }
Beispiel #3
0
 public static void RetailAssert(bool condition, string formatString)
 {
     if (!condition)
     {
         ExAssert.AssertInternal(formatString, null);
     }
 }
Beispiel #4
0
 public static void RetailAssert(bool condition, string formatString, params object[] parameters)
 {
     if (!condition)
     {
         ExAssert.AssertInternal(formatString, parameters);
     }
 }
Beispiel #5
0
 protected SlidingWindow(TimeSpan slidingWindowLength, TimeSpan bucketLength, Func <DateTime> currentTimeProvider)
 {
     SlidingWindow.ValidateSlidingWindowAndBucketLength(slidingWindowLength, bucketLength);
     ExAssert.RetailAssert(currentTimeProvider != null, "Current time provider should not be null.");
     this.BucketLength        = bucketLength;
     this.currentTimeProvider = currentTimeProvider;
     this.creationTime        = this.currentTimeProvider();
     this.NumberOfBuckets     = (int)(slidingWindowLength.Ticks / this.BucketLength.Ticks);
     this.filled = new bool[this.NumberOfBuckets];
 }
 public MultiGranularityPercentileCounter(TimeSpan expiryInterval, TimeSpan granularityInterval, MultiGranularityPercentileCounter.Param[] parameters, CurrentTimeProvider currentTimeProvider)
 {
     this.count = parameters.Length;
     ExAssert.RetailAssert(this.count > 0, "Number of parameters: {0} must be greater than zero.", new object[]
     {
         this.count
     });
     for (int i = 0; i < this.count - 1; i++)
     {
         ExAssert.RetailAssert(parameters[i].Granularity < parameters[i + 1].Granularity, "The granularities must be sorted.");
         ExAssert.RetailAssert(parameters[i].Range < parameters[i + 1].Range, "The ranges  must be sorted.");
         ExAssert.RetailAssert(parameters[i].Range % parameters[i + 1].Granularity == 0L, "The range[i] MOD granularity[i + 1] must be zero.");
     }
     this.percentileCounters = new PercentileCounter[this.count];
     this.borderBuckets      = new long[this.count];
     for (int j = 0; j < this.count; j++)
     {
         this.percentileCounters[j] = new PercentileCounter(expiryInterval, granularityInterval, parameters[j].Granularity, parameters[j].Range, currentTimeProvider);
         this.borderBuckets[j]      = parameters[j].Range - parameters[j].Granularity;
     }
 }
 public Param(long granularity, long range)
 {
     ExAssert.RetailAssert(range % granularity == 0L, "The range MOD granularity must be zero.");
     this.granularity = granularity;
     this.range       = range;
 }