Class AggregatingTrimmer

  • All Implemented Interfaces:
    SlidingWindowTrimmer<java.lang.Long>

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

      Constructors 
      Constructor Description
      AggregatingTrimmer​(long startTime, java.util.concurrent.TimeUnit startUnitTime, long chunkTimeSize, java.util.concurrent.TimeUnit chunkTimeSizeUnit)
      Creates the trimmer that updates the registered time reservoirs with the aggregated measurements for the values it trimmed.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TimeReservoir<java.lang.Long> getTimeReservoirNotifier()  
      (package private) static long lowerBound​(long key, long startTime, long chunkSize, int power)
      Calculates lower bound for given key so that following conditions are true
      private long lowerBound​(java.lang.Long key)  
      void register​(TimeReservoir<AggregatedValueObject> timeReservoirListener)
      Registers given aggregating sliding window reservoir to get updates from this trimmer.
      void setTimeReservoir​(TimeReservoir<java.lang.Long> timeReservoirNotifier)  
      void trim​(java.util.concurrent.ConcurrentNavigableMap<java.lang.Long,​java.lang.Long> map, long key)
      Trim the measurements provided as the map from the head up to the key (not inclusive).
      private long upperBound​(long chunkLowerBound, long key)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • timeReservoirNotifier

        private TimeReservoir<java.lang.Long> timeReservoirNotifier
      • startTime

        private final long startTime
      • startUnitTime

        private final java.util.concurrent.TimeUnit startUnitTime
      • chunkSize

        private final long chunkSize
      • locked

        private final java.util.concurrent.atomic.AtomicBoolean locked
        The lock that prevents other threads to trim the associated reservoir in parallel.
    • Constructor Detail

      • AggregatingTrimmer

        public AggregatingTrimmer​(long startTime,
                                  java.util.concurrent.TimeUnit startUnitTime,
                                  long chunkTimeSize,
                                  java.util.concurrent.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 Detail

      • trim

        public void trim​(java.util.concurrent.ConcurrentNavigableMap<java.lang.Long,​java.lang.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<java.lang.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​(java.lang.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<java.lang.Long> timeReservoirNotifier)
        Specified by:
        setTimeReservoir in interface SlidingWindowTrimmer<java.lang.Long>
        Parameters:
        timeReservoirNotifier - The reservoir that uses this trimmer.
      • getTimeReservoirNotifier

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