class AggregatingTrimmer extends java.lang.Object implements SlidingWindowTrimmer<java.lang.Long>
Modifier and Type | Field and 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 and 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.
|
Modifier and Type | Method and Description |
---|---|
TimeReservoir<java.lang.Long> |
getTimeReservoirNotifier() |
private long |
lowerBound(java.lang.Long key) |
(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
|
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) |
private final java.util.List<TimeReservoir<AggregatedValueObject>> aggregatedReservoirListeners
private TimeReservoir<java.lang.Long> timeReservoirNotifier
private final long startTime
private final java.util.concurrent.TimeUnit startUnitTime
private final long chunkSize
private final java.util.concurrent.atomic.AtomicBoolean locked
public AggregatingTrimmer(long startTime, java.util.concurrent.TimeUnit startUnitTime, long chunkTimeSize, java.util.concurrent.TimeUnit chunkTimeSizeUnit)
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.public void trim(java.util.concurrent.ConcurrentNavigableMap<java.lang.Long,java.lang.Long> map, long key)
SlidingWindowTrimmer
trim
in interface SlidingWindowTrimmer<java.lang.Long>
map
- The map to trim.key
- The key to which trim the map.private long upperBound(long chunkLowerBound, long key)
private long lowerBound(java.lang.Long key)
static long lowerBound(long key, long startTime, long chunkSize, int power)
lowerBound <= key && key < lowerBound + chunkSize
(startTime % chunkSize) <<
power
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.public void register(TimeReservoir<AggregatedValueObject> timeReservoirListener)
timeReservoirListener
- The aggregated sliding window reservoir to update with trimmed measurementspublic void setTimeReservoir(TimeReservoir<java.lang.Long> timeReservoirNotifier)
setTimeReservoir
in interface SlidingWindowTrimmer<java.lang.Long>
timeReservoirNotifier
- The reservoir that uses this trimmer.public TimeReservoir<java.lang.Long> getTimeReservoirNotifier()