LongAdder getAdder(HystrixRollingNumberEvent type) { if (!type.isCounter()) { throw new IllegalStateException("Type is not a Counter: " + type.name()); } return adderForCounterType[type.ordinal()]; }
LongAdder getAdder(HystrixRollingNumberEvent type) { if (!type.isCounter()) { throw new IllegalStateException("Type is not a Counter: " + type.name()); } return adderForCounterType[type.ordinal()]; }
long get(HystrixRollingNumberEvent type) { if (type.isCounter()) { return adderForCounterType[type.ordinal()].sum(); } if (type.isMaxUpdater()) { return updaterForCounterType[type.ordinal()].max(); } throw new IllegalStateException("Unknown type of event: " + type.name()); }
long get(HystrixRollingNumberEvent type) { if (type.isCounter()) { return adderForCounterType[type.ordinal()].sum(); } if (type.isMaxUpdater()) { return updaterForCounterType[type.ordinal()].max(); } throw new IllegalStateException("Unknown type of event: " + type.name()); }
/** * Get an array of values for all buckets in the rolling counter for the given {@link HystrixRollingNumberEvent} type. * <p> * Index 0 is the oldest bucket. * <p> * The {@link HystrixRollingNumberEvent} must be a "counter" type <code>HystrixRollingNumberEvent.isCounter() == true</code>. * * @param type * HystrixRollingNumberEvent defining which counter to retrieve values from * @return array of values from each of the rolling buckets for given {@link HystrixRollingNumberEvent} counter type */ 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.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; for (Bucket bucket : bucketArray) { if (type.isCounter()) { values[i++] = bucket.getAdder(type).sum(); } else if (type.isMaxUpdater()) { values[i++] = bucket.getMaxUpdater(type).max(); } } return values; }
public void addBucket(Bucket lastBucket) { for (HystrixRollingNumberEvent type : HystrixRollingNumberEvent.values()) { if (type.isCounter()) { getAdder(type).add(lastBucket.getAdder(type).sum()); } if (type.isMaxUpdater()) { getMaxUpdater(type).update(lastBucket.getMaxUpdater(type).max()); } } }
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[HystrixRollingNumberEvent.values().length]; for (HystrixRollingNumberEvent type : HystrixRollingNumberEvent.values()) { if (type.isCounter()) { adderForCounterType[type.ordinal()] = new LongAdder(); } } updaterForCounterType = new LongMaxUpdater[HystrixRollingNumberEvent.values().length]; for (HystrixRollingNumberEvent type : HystrixRollingNumberEvent.values()) { if (type.isMaxUpdater()) { updaterForCounterType[type.ordinal()] = new LongMaxUpdater(); // initialize to 0 otherwise it is Long.MIN_VALUE updaterForCounterType[type.ordinal()].update(0); } } }
Bucket(long startTime) { this.windowStart = startTime; /* * 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[HystrixRollingNumberEvent.values().length]; for (HystrixRollingNumberEvent type : HystrixRollingNumberEvent.values()) { if (type.isCounter()) { adderForCounterType[type.ordinal()] = new LongAdder(); } } updaterForCounterType = new LongMaxUpdater[HystrixRollingNumberEvent.values().length]; for (HystrixRollingNumberEvent type : HystrixRollingNumberEvent.values()) { if (type.isMaxUpdater()) { updaterForCounterType[type.ordinal()] = new LongMaxUpdater(); // initialize to 0 otherwise it is Long.MIN_VALUE updaterForCounterType[type.ordinal()].update(0); } } }
LongAdder getAdder(HystrixRollingNumberEvent type) { if (!type.isCounter()) { throw new IllegalStateException("Type is not a Counter: " + type.name()); } return adderForCounterType[type.ordinal()]; }
LongAdder getAdder(HystrixRollingNumberEvent type) { if (!type.isCounter()) { throw new IllegalStateException("Type is not a Counter: " + type.name()); } return adderForCounterType[type.ordinal()]; }
long get(HystrixRollingNumberEvent type) { if (type.isCounter()) { return adderForCounterType[type.ordinal()].sum(); } if (type.isMaxUpdater()) { return updaterForCounterType[type.ordinal()].max(); } throw new IllegalStateException("Unknown type of event: " + type.name()); }
long get(HystrixRollingNumberEvent type) { if (type.isCounter()) { return adderForCounterType[type.ordinal()].sum(); } if (type.isMaxUpdater()) { return updaterForCounterType[type.ordinal()].max(); } throw new IllegalStateException("Unknown type of event: " + type.name()); }
/** * Get an array of values for all buckets in the rolling counter for the given {@link HystrixRollingNumberEvent} type. * <p> * Index 0 is the oldest bucket. * <p> * The {@link HystrixRollingNumberEvent} must be a "counter" type <code>HystrixRollingNumberEvent.isCounter() == true</code>. * * @param type * HystrixRollingNumberEvent defining which counter to retrieve values from * @return array of values from each of the rolling buckets for given {@link HystrixRollingNumberEvent} counter type */ 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.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; for (Bucket bucket : bucketArray) { if (type.isCounter()) { values[i++] = bucket.getAdder(type).sum(); } else if (type.isMaxUpdater()) { values[i++] = bucket.getMaxUpdater(type).max(); } } return values; }
public void addBucket(Bucket lastBucket) { for (HystrixRollingNumberEvent type : HystrixRollingNumberEvent.values()) { if (type.isCounter()) { getAdder(type).add(lastBucket.getAdder(type).sum()); } if (type.isMaxUpdater()) { getMaxUpdater(type).update(lastBucket.getMaxUpdater(type).max()); } } }
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[HystrixRollingNumberEvent.values().length]; for (HystrixRollingNumberEvent type : HystrixRollingNumberEvent.values()) { if (type.isCounter()) { adderForCounterType[type.ordinal()] = new LongAdder(); } } updaterForCounterType = new LongMaxUpdater[HystrixRollingNumberEvent.values().length]; for (HystrixRollingNumberEvent type : HystrixRollingNumberEvent.values()) { if (type.isMaxUpdater()) { updaterForCounterType[type.ordinal()] = new LongMaxUpdater(); // initialize to 0 otherwise it is Long.MIN_VALUE updaterForCounterType[type.ordinal()].update(0); } } }
Bucket(long startTime) { this.windowStart = startTime; /* * 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[HystrixRollingNumberEvent.values().length]; for (HystrixRollingNumberEvent type : HystrixRollingNumberEvent.values()) { if (type.isCounter()) { adderForCounterType[type.ordinal()] = new LongAdder(); } } updaterForCounterType = new LongMaxUpdater[HystrixRollingNumberEvent.values().length]; for (HystrixRollingNumberEvent type : HystrixRollingNumberEvent.values()) { if (type.isMaxUpdater()) { updaterForCounterType[type.ordinal()] = new LongMaxUpdater(); // initialize to 0 otherwise it is Long.MIN_VALUE updaterForCounterType[type.ordinal()].update(0); } } }