private S add(final S event) { S newValue; S value; do { value = ref.get(); newValue = entityAccess.aggregate(value, event); } while (!ref.compareAndSet(value, newValue)); return newValue; }
public S addOrReset(final S event) { // entityAccess.getTimestamp(curValue) represents the time at which the current value // was last updated. If the last value is less than current time - 1 binPrecision, then it // means that we've rolled over and need to reset the value. final long maxExpectedTimePeriod = System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(1, binPrecision); final S curValue = ref.get(); if (entityAccess.getTimestamp(curValue) < maxExpectedTimePeriod) { ref.compareAndSet(curValue, entityAccess.createNew()); } return add(event); } }
public boolean isExpired() { // entityAccess.getTimestamp(curValue) represents the time at which the current value // was last updated. If the last value is less than current time - 1 binPrecision, then it // means that we've rolled over and need to reset the value. final long maxExpectedTimePeriod = System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(numConfiguredBins, binPrecision); final S curValue = ref.get(); return (entityAccess.getTimestamp(curValue) < maxExpectedTimePeriod); }
public boolean isExpired() { // entityAccess.getTimestamp(curValue) represents the time at which the current value // was last updated. If the last value is less than current time - 1 binPrecision, then it // means that we've rolled over and need to reset the value. final long maxExpectedTimePeriod = System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(numConfiguredBins, binPrecision); final S curValue = ref.get(); return (entityAccess.getTimestamp(curValue) < maxExpectedTimePeriod); }
public S addOrReset(final S event) { // entityAccess.getTimestamp(curValue) represents the time at which the current value // was last updated. If the last value is less than current time - 1 binPrecision, then it // means that we've rolled over and need to reset the value. final long maxExpectedTimePeriod = System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(1, binPrecision); final S curValue = ref.get(); if (entityAccess.getTimestamp(curValue) < maxExpectedTimePeriod) { ref.compareAndSet(curValue, entityAccess.createNew()); } return add(event); } }
public T getAggregateValue(final long sinceEpochMillis) { final int startBinIdx = (int) (binPrecision.convert(sinceEpochMillis, TimeUnit.MILLISECONDS) % numBins); T total = null; for (int i = 0; i < numBins; i++) { int binIdx = (startBinIdx + i) % numBins; final EntitySum<T> bin = bins[binIdx]; if (!bin.isExpired()) { total = entityAccess.aggregate(total, bin.getValue()); } } return total; }
private S add(final S event) { S newValue; S value; do { value = ref.get(); newValue = entityAccess.aggregate(value, event); } while (!ref.compareAndSet(value, newValue)); return newValue; }
public T getAggregateValue(final long sinceEpochMillis) { final int startBinIdx = (int) (binPrecision.convert(sinceEpochMillis, TimeUnit.MILLISECONDS) % numBins); T total = null; for (int i = 0; i < numBins; i++) { int binIdx = (startBinIdx + i) % numBins; final EntitySum<T> bin = bins[binIdx]; if (!bin.isExpired()) { total = entityAccess.aggregate(total, bin.getValue()); } } return total; }