public class SmoothlyDecayingRollingCounter extends Object implements WindowCounter
Concurrency properties:
Usage recommendations:
Performance considerations:
Example of usage:
// constructs the counter which divided by 10 chunks with 60 seconds time window.
// one chunk will be reset to zero after each 6 second,
WindowCounter counter = new SmoothlyDecayingRollingCounter(Duration.ofSeconds(60), 10);
counter.add(42);
| Constructor and Description |
|---|
SmoothlyDecayingRollingCounter(Duration rollingWindow,
int numberChunks)
Constructs the chunked counter divided by
numberChunks. |
SmoothlyDecayingRollingCounter(Duration rollingWindow,
int numberChunks,
Ticker ticker) |
| Modifier and Type | Method and Description |
|---|---|
void |
add(long delta)
Increment the counter by
delta. |
int |
getChunkCount() |
Duration |
getRollingWindow() |
long |
getSum()
Returns the counter's current value.
|
String |
toString() |
public SmoothlyDecayingRollingCounter(Duration rollingWindow, int numberChunks)
numberChunks.
The counter will invalidate one chunk each time when rollingWindow/numberChunks millis has elapsed,
except oldest chunk which invalidated continuously.
The memory consumed by counter and latency of sum calculation depend directly from numberChunks
Example of usage:
// constructs the counter which divided by 10 chunks with 60 seconds time window.
// one chunk will be reset to zero after each 6 second,
WindowCounter counter = new SmoothlyDecayingRollingCounter(Duration.ofSeconds(60), 10);
counter.add(42);
rollingWindow - the rolling time window durationnumberChunks - The count of chunk to split counterpublic Duration getRollingWindow()
public int getChunkCount()
public void add(long delta)
WindowCounterdelta.
If You want to decrement instead of increment then use negative delta.add in interface WindowCounterdelta - the amount by which the counter will be increasedpublic long getSum()
WindowCountergetSum in interface WindowCounterCopyright © 2020. All rights reserved.