/** * Returns the {@link #max} as an {@code int} after a narrowing * primitive conversion. */ public int intValue() { return (int)max(); }
/** * Updates the maximum to be at least the given value. * * @param x the value to update */ public void update(long x) { Cell[] as; long b, v; HashCode hc; Cell a; int n; if ((as = cells) != null || (b = base) < x && !casBase(b, x)) { boolean uncontended = true; int h = (hc = threadHashCode.get()).code; if (as == null || (n = as.length) < 1 || (a = as[(n - 1) & h]) == null || ((v = a.value) < x && !(uncontended = a.cas(v, x)))) retryUpdate(x, hc, uncontended); } }
/** * Resets variables maintaining updates to {@code Long.MIN_VALUE}. * This method may be a useful alternative to creating a new * updater, but is only effective if there are no concurrent * updates. Because this method is intrinsically racy, it should * only be used when it is known that no threads are concurrently * updating. */ public void reset() { internalReset(Long.MIN_VALUE); }
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); } } }
/** * Update a value and retain the max value. * <p> * The {@link HystrixRollingNumberEvent} must be a "max updater" type <code>HystrixRollingNumberEvent.isMaxUpdater() == true</code>. * * @param type HystrixRollingNumberEvent defining which counter to retrieve values from * @param value long value to be given to the max updater */ public void updateRollingMax(HystrixRollingNumberEvent type, long value) { getCurrentBucket().getMaxUpdater(type).update(value); }
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); } } }
/** * Update a value and retain the max value. * <p> * The {@link HystrixRollingNumberEvent} must be a "max updater" type <code>HystrixRollingNumberEvent.isMaxUpdater() == true</code>. * * @param type HystrixRollingNumberEvent defining which counter to retrieve values from * @param value long value to be given to the max updater */ public void updateRollingMax(HystrixRollingNumberEvent type, long value) { getCurrentBucket().getMaxUpdater(type).update(value); }
/** * Returns the {@link #max} as a {@code double} after a widening * primitive conversion. */ public double doubleValue() { return (double)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); } } }
/** * Updates the maximum to be at least the given value. * * @param x the value to update */ public void update(long x) { Cell[] as; long b, v; HashCode hc; Cell a; int n; if ((as = cells) != null || (b = base) < x && !casBase(b, x)) { boolean uncontended = true; int h = (hc = threadHashCode.get()).code; if (as == null || (n = as.length) < 1 || (a = as[(n - 1) & h]) == null || ((v = a.value) < x && !(uncontended = a.cas(v, x)))) retryUpdate(x, hc, uncontended); } }
/** * Resets variables maintaining updates to {@code Long.MIN_VALUE}. * This method may be a useful alternative to creating a new * updater, but is only effective if there are no concurrent * updates. Because this method is intrinsically racy, it should * only be used when it is known that no threads are concurrently * updating. */ public void reset() { internalReset(Long.MIN_VALUE); }
/** * Returns the {@link #max} as a {@code float} * after a widening primitive conversion. */ public float floatValue() { return (float)max(); }
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); } } }
/** * Equivalent to {@link #max}. * * @return the maximum */ public long longValue() { return max(); }
/** * Returns the String representation of the {@link #max}. * @return the String representation of the {@link #max} */ public String toString() { return Long.toString(max()); }
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { s.defaultWriteObject(); s.writeLong(max()); }
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()); }