Package com.codahale.metrics
Class SlidingTimeWindowReservoir
java.lang.Object
com.codahale.metrics.SlidingTimeWindowReservoir
- All Implemented Interfaces:
Reservoir
A
Reservoir
implementation backed by a sliding window that stores only the measurements made
in the last N
seconds (or other time unit).-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Clock
private static final int
private final AtomicLong
private final AtomicLong
private final ConcurrentSkipListMap
<Long, Long> private static final int
private final long
-
Constructor Summary
ConstructorsConstructorDescriptionSlidingTimeWindowReservoir
(long window, TimeUnit windowUnit) Creates a newSlidingTimeWindowReservoir
with the given window of time.SlidingTimeWindowReservoir
(long window, TimeUnit windowUnit, Clock clock) Creates a newSlidingTimeWindowReservoir
with the given clock and window of time. -
Method Summary
-
Field Details
-
COLLISION_BUFFER
private static final int COLLISION_BUFFER- See Also:
-
TRIM_THRESHOLD
private static final int TRIM_THRESHOLD- See Also:
-
clock
-
measurements
-
window
private final long window -
lastTick
-
count
-
-
Constructor Details
-
SlidingTimeWindowReservoir
Creates a newSlidingTimeWindowReservoir
with the given window of time.- Parameters:
window
- the window of timewindowUnit
- the unit ofwindow
-
SlidingTimeWindowReservoir
Creates a newSlidingTimeWindowReservoir
with the given clock and window of time.- Parameters:
window
- the window of timewindowUnit
- the unit ofwindow
clock
- theClock
to use
-
-
Method Details
-
size
public int size()Description copied from interface:Reservoir
Returns the number of values recorded. -
update
public void update(long value) Description copied from interface:Reservoir
Adds a new recorded value to the reservoir. -
getSnapshot
Description copied from interface:Reservoir
Returns a snapshot of the reservoir's values.- Specified by:
getSnapshot
in interfaceReservoir
- Returns:
- a snapshot of the reservoir's values
-
getTick
private long getTick() -
trim
private void trim()
-