Class AggregatingTrimmer

java.lang.Object
org.glassfish.jersey.server.internal.monitoring.AggregatingTrimmer
All Implemented Interfaces:
SlidingWindowTrimmer<Long>

class AggregatingTrimmer extends Object implements SlidingWindowTrimmer<Long>
An aggregating trimmer for sliding window measurements. This trimmer updates registered time reservoirs with the aggregated measurements for the values it trimmed.
  • Field Details

    • aggregatedReservoirListeners

      private final List<TimeReservoir<AggregatedValueObject>> aggregatedReservoirListeners
    • timeReservoirNotifier

      private TimeReservoir<Long> timeReservoirNotifier
    • startTime

      private final long startTime
    • startUnitTime

      private final TimeUnit startUnitTime
    • chunkSize

      private final long chunkSize
    • locked

      private final AtomicBoolean locked
      The lock that prevents other threads to trim the associated reservoir in parallel.
  • Constructor Details

    • AggregatingTrimmer

      public AggregatingTrimmer(long startTime, TimeUnit startUnitTime, long chunkTimeSize, TimeUnit chunkTimeSizeUnit)
      Creates the trimmer that updates the registered time reservoirs with the aggregated measurements for the values it trimmed.
      Parameters:
      startTime - The start time that determines the offset for the chunks.
      startUnitTime - The time unit of the start time.
      chunkTimeSize - The size of one "time chunk".
      chunkTimeSizeUnit - The time unit of the time chunk.
  • Method Details

    • trim

      public void trim(ConcurrentNavigableMap<Long,Long> map, long key)
      Description copied from interface: SlidingWindowTrimmer
      Trim the measurements provided as the map from the head up to the key (not inclusive).
      Specified by:
      trim in interface SlidingWindowTrimmer<Long>
      Parameters:
      map - The map to trim.
      key - The key to which trim the map.
    • upperBound

      private long upperBound(long chunkLowerBound, long key)
    • lowerBound

      private long lowerBound(Long key)
    • lowerBound

      static long lowerBound(long key, long startTime, long chunkSize, int power)
      Calculates lower bound for given key so that following conditions are true
      • lowerBound <= key && key < lowerBound + chunkSize
      • The lower bound is a multiple of chunk size with an offset calculated as (startTime % chunkSize) << power
      Note the offset calculation is determined by start time because not always one lower bound from the sequence of all lower bounds for given arguments is equal to 0.
      The power is used to shift the offset because all the keys are also expected to be shifted with the power.
      Parameters:
      key - The key to find the lower bound for.
      startTime - The start time that determines the offset for the chunks.
      chunkSize - The size of one chunk.
      power - The power the keys are expected to be shifted with.
      Returns:
      The lower bound for given arguments satisfying conditions stated above.
    • register

      public void register(TimeReservoir<AggregatedValueObject> timeReservoirListener)
      Registers given aggregating sliding window reservoir to get updates from this trimmer.
      Parameters:
      timeReservoirListener - The aggregated sliding window reservoir to update with trimmed measurements
    • setTimeReservoir

      public void setTimeReservoir(TimeReservoir<Long> timeReservoirNotifier)
      Specified by:
      setTimeReservoir in interface SlidingWindowTrimmer<Long>
      Parameters:
      timeReservoirNotifier - The reservoir that uses this trimmer.
    • getTimeReservoirNotifier

      public TimeReservoir<Long> getTimeReservoirNotifier()
      Returns:
      The reservoir that produces the data this trimmer aggregates and trims.