Class AbstractSlidingWindowTimeReservoir<V>
java.lang.Object
org.glassfish.jersey.server.internal.monitoring.core.AbstractSlidingWindowTimeReservoir<V>
- Type Parameters:
V
- The type of values to store in this sliding window reservoir
- All Implemented Interfaces:
TimeReservoir<V>
public abstract class AbstractSlidingWindowTimeReservoir<V>
extends Object
implements TimeReservoir<V>
An abstract
TimeReservoir
implementation backed by a sliding window that stores only the measurements made in the last
N
seconds (or other startTime unit) and allows an update with data that happened in past (which is what makes it
different from Dropwizard's Metrics SlidingTimeWindowReservoir.
The snapshot this reservoir returns has limitations as mentioned in TimeReservoir
.
This reservoir is capable to store up to 2^ReservoirConstants.COLLISION_BUFFER_POWER
, that is 256, in a granularity of
nanoseconds. In other words, up to 256 values that occurred at the same nanosecond can be stored in this reservoir. For
particular nanosecond, if the collision buffer exceeds, newly added values are thrown away.- Author:
- Stepan Vavra
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractSlidingWindowTimeReservoir
(long window, TimeUnit windowUnit, long startTime, TimeUnit startTimeUnit) Creates a newSlidingWindowTimeReservoir
with the start time and window of startTime.AbstractSlidingWindowTimeReservoir
(long window, TimeUnit windowUnit, long startTime, TimeUnit startTimeUnit, SlidingWindowTrimmer<V> trimmer) Creates a new base sliding time window reservoir with the start time and a specified time window. -
Method Summary
Modifier and TypeMethodDescriptiongetSnapshot
(long time, TimeUnit timeUnit) Returns a snapshot of the reservoir's values at given time or newer.long
The time interval this reservoir stores data of.int
Returns the number of values recorded at given time or newer.protected abstract UniformTimeSnapshot
snapshot
(Collection<V> values, long timeInterval, TimeUnit timeIntervalUnit, long time, TimeUnit timeUnit) Subclasses are required to instantiateUniformTimeSnapshot
on their own.void
Adds a new recorded value to the reservoir bound to a given time.
-
Constructor Details
-
AbstractSlidingWindowTimeReservoir
public AbstractSlidingWindowTimeReservoir(long window, TimeUnit windowUnit, long startTime, TimeUnit startTimeUnit) Creates a newSlidingWindowTimeReservoir
with the start time and window of startTime.- Parameters:
window
- The window of startTimewindowUnit
- The unit ofwindow
startTime
- The start time from which this reservoir calculates measurementsstartTimeUnit
- The start time unit
-
AbstractSlidingWindowTimeReservoir
public AbstractSlidingWindowTimeReservoir(long window, TimeUnit windowUnit, long startTime, TimeUnit startTimeUnit, SlidingWindowTrimmer<V> trimmer) Creates a new base sliding time window reservoir with the start time and a specified time window.- Parameters:
window
- The window of startTime.windowUnit
- The unit ofwindow
.startTime
- The start time from which this reservoir calculates measurements.startTimeUnit
- The start time unit.trimmer
- The trimmer to use for trimming, ifnull
, default trimmer is used.
-
-
Method Details
-
size
Description copied from interface:TimeReservoir
Returns the number of values recorded at given time or newer. It may not be supported to return a size in past due to performance optimizations.- Specified by:
size
in interfaceTimeReservoir<V>
- Parameters:
time
- The time to get the size fortimeUnit
- Time unit of the provided time- Returns:
- the number of values recorded for given time or newer
-
update
Description copied from interface:TimeReservoir
Adds a new recorded value to the reservoir bound to a given time.- Specified by:
update
in interfaceTimeReservoir<V>
- Parameters:
value
- a new recorded valuetime
- The time the recorded value occurred attimeUnit
- Time unit of the provided time
-
interval
Description copied from interface:TimeReservoir
The time interval this reservoir stores data of.- Specified by:
interval
in interfaceTimeReservoir<V>
- Parameters:
timeUnit
- The time unit in which to get the interval- Returns:
- The time interval of this time reservoir
-
snapshot
protected abstract UniformTimeSnapshot snapshot(Collection<V> values, long timeInterval, TimeUnit timeIntervalUnit, long time, TimeUnit timeUnit) Subclasses are required to instantiateUniformTimeSnapshot
on their own.- Parameters:
values
- The values to create the snapshot fromtimeInterval
- The time interval this snapshot conforms totimeIntervalUnit
- The interval unit of the time intervaltime
- The time of the request of the snapshottimeUnit
- The unit of the time of the snapshot request- Returns:
- The snapshot
-
getSnapshot
Description copied from interface:TimeReservoir
Returns a snapshot of the reservoir's values at given time or newer. It may not be supported to return a snapshot in past due to performance optimizations.- Specified by:
getSnapshot
in interfaceTimeReservoir<V>
- Parameters:
time
- The time for which to get the snapshottimeUnit
- Time unit of the provided time- Returns:
- a snapshot of the reservoir's values for given time or newer
-