Class AggregatingTrimmer
- java.lang.Object
-
- org.glassfish.jersey.server.internal.monitoring.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.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<TimeReservoir<AggregatedValueObject>>
aggregatedReservoirListeners
private long
chunkSize
private java.util.concurrent.atomic.AtomicBoolean
locked
The lock that prevents other threads to trim the associated reservoir in parallel.private long
startTime
private java.util.concurrent.TimeUnit
startUnitTime
private TimeReservoir<java.lang.Long>
timeReservoirNotifier
-
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 trueprivate 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)
-
-
-
Field Detail
-
aggregatedReservoirListeners
private final java.util.List<TimeReservoir<AggregatedValueObject>> aggregatedReservoirListeners
-
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 interfaceSlidingWindowTrimmer<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 truelowerBound <= key && key < lowerBound + chunkSize
- The lower bound is a multiple of chunk size with an offset calculated as
(startTime % chunkSize) << power
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 interfaceSlidingWindowTrimmer<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.
-
-