示例#1
0
 /// <summary>
 /// Gets the cumulative value for the specified <see cref="RollingNumberEvent"/>.
 /// (Returns <see cref="LongAdder.Sum()"/> for Counter types and <see cref="LongMaxUpdater.Max()"/> for MaxUpdater types.)
 /// </summary>
 /// <param name="type">The specified event.</param>
 /// <returns>The cumulative value for the specified event.</returns>
 public long Get(RollingNumberEvent type)
 {
     if (type.IsCounter())
     {
         return this.adderForCounterType[(int)type].Sum();
     }
     else if (type.IsMaxUpdater())
     {
         return this.updaterForCounterType[(int)type].Max();
     }
     else
     {
         throw new ArgumentException(string.Format("Unknown type of event: {0}", type), "type");
     }
 }
示例#2
0
            /// <summary>
            /// Gets the <see cref="LongAdder"/> instance for the specified event.
            /// </summary>
            /// <param name="type">The specified event.</param>
            /// <returns>The <see cref="LongAdder"/> instance for the specified event.</returns>
            public LongAdder GetAdder(RollingNumberEvent type)
            {
                if (!type.IsCounter())
                {
                    throw new ArgumentException(string.Format("Type is not a Counter: {0}", type), "type");
                }

                return this.adderForCounterType[(int)type];
            }
示例#3
0
        /// <summary>
        /// Get an array of values for all buckets in the rolling counter for the given <see cref="RollingNumberEvent"/> type.
        /// Index 0 is the oldest bucket.
        /// The <see cref="RollingNumberEvent"/> must be a "Counter" type (HystrixRollingNumberEvent.IsCounter() == true).
        /// </summary>
        /// <param name="type">HystrixRollingNumberEvent defining which counter to retrieve values from</param>
        /// <returns>Array of values from each of the rolling buckets for given <see cref="RollingNumberEvent"/> counter type</returns>
        public long[] GetValues(RollingNumberEvent type)
        {
            if (this.GetCurrentBucket() == 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 = this.buckets.GetArray();

            // 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 (type.IsCounter())
                {
                    values[i++] = bucket.GetAdder(type).Sum();
                }
                else if (type.IsMaxUpdater())
                {
                    values[i++] = bucket.GetMaxUpdater(type).Max();
                }
            }

            return values;
        }