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 abstractTimeReservoirimplementation backed by a sliding window that stores only the measurements made in the lastNseconds (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 inTimeReservoir. 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:
Dropwizard's Metrics SlidingTimeWindowReservoir
-
-
Constructor Summary
Constructors Constructor Description AbstractSlidingWindowTimeReservoir(long window, TimeUnit windowUnit, long startTime, TimeUnit startTimeUnit)Creates a newSlidingWindowTimeReservoirwith 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
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description UniformTimeSnapshotgetSnapshot(long time, TimeUnit timeUnit)Returns a snapshot of the reservoir's values at given time or newer.longinterval(TimeUnit timeUnit)The time interval this reservoir stores data of.intsize(long time, TimeUnit timeUnit)Returns the number of values recorded at given time or newer.protected abstract UniformTimeSnapshotsnapshot(Collection<V> values, long timeInterval, TimeUnit timeIntervalUnit, long time, TimeUnit timeUnit)Subclasses are required to instantiateUniformTimeSnapshoton their own.voidupdate(V value, long time, TimeUnit timeUnit)Adds a new recorded value to the reservoir bound to a given time.
-
-
-
Constructor Detail
-
AbstractSlidingWindowTimeReservoir
public AbstractSlidingWindowTimeReservoir(long window, TimeUnit windowUnit, long startTime, TimeUnit startTimeUnit)Creates a newSlidingWindowTimeReservoirwith the start time and window of startTime.- Parameters:
window- The window of startTimewindowUnit- The unit ofwindowstartTime- 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 Detail
-
size
public int size(long time, TimeUnit timeUnit)Description copied from interface:TimeReservoirReturns 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:
sizein 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
public void update(V value, long time, TimeUnit timeUnit)
Description copied from interface:TimeReservoirAdds a new recorded value to the reservoir bound to a given time.- Specified by:
updatein interfaceTimeReservoir<V>- Parameters:
value- a new recorded valuetime- The time the recorded value occurred attimeUnit- Time unit of the provided time
-
interval
public long interval(TimeUnit timeUnit)
Description copied from interface:TimeReservoirThe time interval this reservoir stores data of.- Specified by:
intervalin 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 instantiateUniformTimeSnapshoton 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
public UniformTimeSnapshot getSnapshot(long time, TimeUnit timeUnit)
Description copied from interface:TimeReservoirReturns 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:
getSnapshotin 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
-
-