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 Details

    • AbstractSlidingWindowTimeReservoir

      public AbstractSlidingWindowTimeReservoir(long window, TimeUnit windowUnit, long startTime, TimeUnit startTimeUnit)
      Creates a new SlidingWindowTimeReservoir with the start time and window of startTime.
      Parameters:
      window - The window of startTime
      windowUnit - The unit of window
      startTime - The start time from which this reservoir calculates measurements
      startTimeUnit - 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 of window.
      startTime - The start time from which this reservoir calculates measurements.
      startTimeUnit - The start time unit.
      trimmer - The trimmer to use for trimming, if null, default trimmer is used.
  • Method Details

    • size

      public int size(long time, TimeUnit timeUnit)
      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 interface TimeReservoir<V>
      Parameters:
      time - The time to get the size for
      timeUnit - 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: TimeReservoir
      Adds a new recorded value to the reservoir bound to a given time.
      Specified by:
      update in interface TimeReservoir<V>
      Parameters:
      value - a new recorded value
      time - The time the recorded value occurred at
      timeUnit - Time unit of the provided time
    • interval

      public long interval(TimeUnit timeUnit)
      Description copied from interface: TimeReservoir
      The time interval this reservoir stores data of.
      Specified by:
      interval in interface TimeReservoir<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 instantiate UniformTimeSnapshot on their own.
      Parameters:
      values - The values to create the snapshot from
      timeInterval - The time interval this snapshot conforms to
      timeIntervalUnit - The interval unit of the time interval
      time - The time of the request of the snapshot
      timeUnit - The unit of the time of the snapshot request
      Returns:
      The snapshot
    • getSnapshot

      public UniformTimeSnapshot getSnapshot(long time, TimeUnit timeUnit)
      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 interface TimeReservoir<V>
      Parameters:
      time - The time for which to get the snapshot
      timeUnit - Time unit of the provided time
      Returns:
      a snapshot of the reservoir's values for given time or newer