Example #1
0
            public CumulativeSum()
            {
                /*
                 * We support both LongAdder and LongMaxUpdater in a bucket but don't want the memory allocation
                 * of all types for each so we only allocate the objects if the HystrixRollingNumberEvent matches
                 * the correct type - though we still have the allocation of empty arrays to the given length
                 * as we want to keep using the type.ordinal() value for fast random access.
                 */

                // initialize the array of LongAdders
                _adderForCounterType = new LongAdder[HystrixRollingNumberEventHelper.Values.Count];
                foreach (HystrixRollingNumberEvent type in HystrixRollingNumberEventHelper.Values)
                {
                    if (HystrixRollingNumberEventHelper.IsCounter(type))
                    {
                        _adderForCounterType[(int)type] = new LongAdder();
                    }
                }

                _updaterForCounterType = new LongMaxUpdater[HystrixRollingNumberEventHelper.Values.Count];
                foreach (HystrixRollingNumberEvent type in HystrixRollingNumberEventHelper.Values)
                {
                    if (HystrixRollingNumberEventHelper.IsMaxUpdater(type))
                    {
                        _updaterForCounterType[(int)type] = new LongMaxUpdater();

                        // initialize to 0 otherwise it is Long.MIN_VALUE
                        _updaterForCounterType[(int)type].Update(0);
                    }
                }
            }
Example #2
0
        public long[] GetValues(HystrixRollingNumberEvent type)
        {
            Bucket lastBucket = GetCurrentBucket();

            if (lastBucket == null)
            {
                return(new long[0]);
            }

            // get buckets as an array (which is a copy of the current state at this point in time)
            Bucket[] bucketArray = _buckets.Array;

            // we have bucket data so we'll return an array of values for all buckets
            long[] values = new long[bucketArray.Length];
            int    i      = 0;

            foreach (Bucket bucket in bucketArray)
            {
                if (HystrixRollingNumberEventHelper.IsCounter(type))
                {
                    values[i++] = bucket.GetAdder(type).Sum();
                }
                else if (HystrixRollingNumberEventHelper.IsMaxUpdater(type))
                {
                    values[i++] = bucket.GetMaxUpdater(type).Max;
                }
            }

            return(values);
        }
 public LongMaxUpdater GetMaxUpdater(HystrixRollingNumberEvent type)
 {
     if (!HystrixRollingNumberEventHelper.IsMaxUpdater(type))
     {
         throw new InvalidOperationException("Type is not a MaxUpdater: " + type.ToString());
     }
     return(updaterForCounterType[(int)type]);
 }
 public long Get(HystrixRollingNumberEvent type)
 {
     if (HystrixRollingNumberEventHelper.IsCounter(type))
     {
         return(adderForCounterType[(int)type].Sum());
     }
     if (HystrixRollingNumberEventHelper.IsMaxUpdater(type))
     {
         return(updaterForCounterType[(int)type].Max);
     }
     throw new InvalidOperationException("Unknown type of event: " + type.ToString());
 }
 public void AddBucket(Bucket lastBucket)
 {
     foreach (HystrixRollingNumberEvent type in HystrixRollingNumberEventHelper.Values)
     {
         if (HystrixRollingNumberEventHelper.IsCounter(type))
         {
             GetAdder(type).Add(lastBucket.GetAdder(type).Sum());
         }
         if (HystrixRollingNumberEventHelper.IsMaxUpdater(type))
         {
             GetMaxUpdater(type).Update(lastBucket.GetMaxUpdater(type).Max);
         }
     }
 }