/** * Create a new builder. */ @SuppressWarnings("MagicNumber") public Builder() { final long nowMillis = System.currentTimeMillis(); final AggregatingTrimmer trimmer = new AggregatingTrimmer(nowMillis, TimeUnit.MILLISECONDS, 1, TimeUnit.SECONDS); final TimeWindowStatisticsImpl.Builder<Long> oneSecondIntervalWindowBuilder = new TimeWindowStatisticsImpl.Builder<>( new SlidingWindowTimeReservoir(1, TimeUnit.SECONDS, nowMillis, TimeUnit.MILLISECONDS, trimmer)); final TimeWindowStatisticsImpl.Builder<Long> infiniteIntervalWindowBuilder = new TimeWindowStatisticsImpl.Builder<>(new UniformTimeReservoir(nowMillis, TimeUnit.MILLISECONDS)); this.updatableIntervalStatistics = Arrays.asList(infiniteIntervalWindowBuilder, oneSecondIntervalWindowBuilder); // create unmodifiable map to ensure that an iteration in the build() won't have multi-threading issues final HashMap<Long, TimeWindowStatisticsImpl.Builder> tmpIntervalStatistics = new HashMap<>(6); // Add approximate infinite time window builder tmpIntervalStatistics.put(0L, infiniteIntervalWindowBuilder); // Add precise 1 second time window builder tmpIntervalStatistics.put(TimeUnit.SECONDS.toMillis(1), oneSecondIntervalWindowBuilder); // Add aggregated 15 seconds time window builder addAggregatedInterval(tmpIntervalStatistics, nowMillis, 15, TimeUnit.SECONDS, trimmer); // Add aggregated 1 minute time window builder addAggregatedInterval(tmpIntervalStatistics, nowMillis, 1, TimeUnit.MINUTES, trimmer); // Add aggregated 15 minutes time window builder addAggregatedInterval(tmpIntervalStatistics, nowMillis, 15, TimeUnit.MINUTES, trimmer); // Add aggregated 1 hour time window builder addAggregatedInterval(tmpIntervalStatistics, nowMillis, 1, TimeUnit.HOURS, trimmer); this.intervalStatistics = Collections.unmodifiableMap(tmpIntervalStatistics); }
final long time, final TimeUnit timeUnit) { final UniformTimeSnapshot notTrimmedMeasurementsSnapshot = notifier.getTimeReservoirNotifier() .getSnapshot(time, timeUnit);
long chunkLowerBound = lowerBound(firstEntry.getKey()); long chunkUpperBound = upperBound(chunkLowerBound, key);
private long lowerBound(final Long key) { return lowerBound(key, TimeUnit.NANOSECONDS.convert(startTime, startUnitTime), chunkSize, COLLISION_BUFFER_POWER); }
/** * Creates an aggregated sliding window reservoir. * * @param window The time size of the window * @param windowUnit The unit of the window size * @param startTime The start time from when to calculate the statistics * @param startTimeUnit The unit of the start time * @param notifier The aggregating trimmer that produces the aggregated data */ public AggregatedSlidingWindowTimeReservoir( final long window, final TimeUnit windowUnit, final long startTime, final TimeUnit startTimeUnit, final AggregatingTrimmer notifier) { super(window, windowUnit, startTime, startTimeUnit); this.notifier = notifier; notifier.register(this); }
private long lowerBound(final Long key) { return lowerBound(key, TimeUnit.NANOSECONDS.convert(startTime, startUnitTime), chunkSize, COLLISION_BUFFER_POWER); }
/** * Creates an aggregated sliding window reservoir. * * @param window The time size of the window * @param windowUnit The unit of the window size * @param startTime The start time from when to calculate the statistics * @param startTimeUnit The unit of the start time * @param notifier The aggregating trimmer that produces the aggregated data */ public AggregatedSlidingWindowTimeReservoir( final long window, final TimeUnit windowUnit, final long startTime, final TimeUnit startTimeUnit, final AggregatingTrimmer notifier) { super(window, windowUnit, startTime, startTimeUnit); this.notifier = notifier; notifier.register(this); }
long chunkLowerBound = lowerBound(firstEntry.getKey()); long chunkUpperBound = upperBound(chunkLowerBound, key);
private long lowerBound(final Long key) { return lowerBound(key, TimeUnit.NANOSECONDS.convert(startTime, startUnitTime), chunkSize, COLLISION_BUFFER_POWER); }
/** * Creates an aggregated sliding window reservoir. * * @param window The time size of the window * @param windowUnit The unit of the window size * @param startTime The start time from when to calculate the statistics * @param startTimeUnit The unit of the start time * @param notifier The aggregating trimmer that produces the aggregated data */ public AggregatedSlidingWindowTimeReservoir( final long window, final TimeUnit windowUnit, final long startTime, final TimeUnit startTimeUnit, final AggregatingTrimmer notifier) { super(window, windowUnit, startTime, startTimeUnit); this.notifier = notifier; notifier.register(this); }
/** * Create a new builder. */ @SuppressWarnings("MagicNumber") public Builder() { final long nowMillis = System.currentTimeMillis(); final AggregatingTrimmer trimmer = new AggregatingTrimmer(nowMillis, TimeUnit.MILLISECONDS, 1, TimeUnit.SECONDS); final TimeWindowStatisticsImpl.Builder<Long> oneSecondIntervalWindowBuilder = new TimeWindowStatisticsImpl.Builder<>( new SlidingWindowTimeReservoir(1, TimeUnit.SECONDS, nowMillis, TimeUnit.MILLISECONDS, trimmer)); final TimeWindowStatisticsImpl.Builder<Long> infiniteIntervalWindowBuilder = new TimeWindowStatisticsImpl.Builder<>(new UniformTimeReservoir(nowMillis, TimeUnit.MILLISECONDS)); this.updatableIntervalStatistics = Arrays.asList(infiniteIntervalWindowBuilder, oneSecondIntervalWindowBuilder); // create unmodifiable map to ensure that an iteration in the build() won't have multi-threading issues final HashMap<Long, TimeWindowStatisticsImpl.Builder> tmpIntervalStatistics = new HashMap<>(6); // Add approximate infinite time window builder tmpIntervalStatistics.put(0L, infiniteIntervalWindowBuilder); // Add precise 1 second time window builder tmpIntervalStatistics.put(TimeUnit.SECONDS.toMillis(1), oneSecondIntervalWindowBuilder); // Add aggregated 15 seconds time window builder addAggregatedInterval(tmpIntervalStatistics, nowMillis, 15, TimeUnit.SECONDS, trimmer); // Add aggregated 1 minute time window builder addAggregatedInterval(tmpIntervalStatistics, nowMillis, 1, TimeUnit.MINUTES, trimmer); // Add aggregated 15 minutes time window builder addAggregatedInterval(tmpIntervalStatistics, nowMillis, 15, TimeUnit.MINUTES, trimmer); // Add aggregated 1 hour time window builder addAggregatedInterval(tmpIntervalStatistics, nowMillis, 1, TimeUnit.HOURS, trimmer); this.intervalStatistics = Collections.unmodifiableMap(tmpIntervalStatistics); }
final long time, final TimeUnit timeUnit) { final UniformTimeSnapshot notTrimmedMeasurementsSnapshot = notifier.getTimeReservoirNotifier() .getSnapshot(time, timeUnit);
long chunkLowerBound = lowerBound(firstEntry.getKey()); long chunkUpperBound = upperBound(chunkLowerBound, key);
private long lowerBound(final Long key) { return lowerBound(key, TimeUnit.NANOSECONDS.convert(startTime, startUnitTime), chunkSize, COLLISION_BUFFER_POWER); }
/** * Creates an aggregated sliding window reservoir. * * @param window The time size of the window * @param windowUnit The unit of the window size * @param startTime The start time from when to calculate the statistics * @param startTimeUnit The unit of the start time * @param notifier The aggregating trimmer that produces the aggregated data */ public AggregatedSlidingWindowTimeReservoir( final long window, final TimeUnit windowUnit, final long startTime, final TimeUnit startTimeUnit, final AggregatingTrimmer notifier) { super(window, windowUnit, startTime, startTimeUnit); this.notifier = notifier; notifier.register(this); }
/** * Create a new builder. */ @SuppressWarnings("MagicNumber") public Builder() { final long nowMillis = System.currentTimeMillis(); final AggregatingTrimmer trimmer = new AggregatingTrimmer(nowMillis, TimeUnit.MILLISECONDS, 1, TimeUnit.SECONDS); final TimeWindowStatisticsImpl.Builder<Long> oneSecondIntervalWindowBuilder = new TimeWindowStatisticsImpl.Builder<>( new SlidingWindowTimeReservoir(1, TimeUnit.SECONDS, nowMillis, TimeUnit.MILLISECONDS, trimmer)); final TimeWindowStatisticsImpl.Builder<Long> infiniteIntervalWindowBuilder = new TimeWindowStatisticsImpl.Builder<>(new UniformTimeReservoir(nowMillis, TimeUnit.MILLISECONDS)); this.updatableIntervalStatistics = Arrays.asList(infiniteIntervalWindowBuilder, oneSecondIntervalWindowBuilder); // create unmodifiable map to ensure that an iteration in the build() won't have multi-threading issues final HashMap<Long, TimeWindowStatisticsImpl.Builder> tmpIntervalStatistics = new HashMap<>(6); // Add approximate infinite time window builder tmpIntervalStatistics.put(0L, infiniteIntervalWindowBuilder); // Add precise 1 second time window builder tmpIntervalStatistics.put(TimeUnit.SECONDS.toMillis(1), oneSecondIntervalWindowBuilder); // Add aggregated 15 seconds time window builder addAggregatedInterval(tmpIntervalStatistics, nowMillis, 15, TimeUnit.SECONDS, trimmer); // Add aggregated 1 minute time window builder addAggregatedInterval(tmpIntervalStatistics, nowMillis, 1, TimeUnit.MINUTES, trimmer); // Add aggregated 15 minutes time window builder addAggregatedInterval(tmpIntervalStatistics, nowMillis, 15, TimeUnit.MINUTES, trimmer); // Add aggregated 1 hour time window builder addAggregatedInterval(tmpIntervalStatistics, nowMillis, 1, TimeUnit.HOURS, trimmer); this.intervalStatistics = Collections.unmodifiableMap(tmpIntervalStatistics); }
final long time, final TimeUnit timeUnit) { final UniformTimeSnapshot notTrimmedMeasurementsSnapshot = notifier.getTimeReservoirNotifier() .getSnapshot(time, timeUnit);
long chunkLowerBound = lowerBound(firstEntry.getKey()); long chunkUpperBound = upperBound(chunkLowerBound, key);
private long lowerBound(final Long key) { return lowerBound(key, TimeUnit.NANOSECONDS.convert(startTime, startUnitTime), chunkSize, COLLISION_BUFFER_POWER); }
/** * Creates an aggregated sliding window reservoir. * * @param window The time size of the window * @param windowUnit The unit of the window size * @param startTime The start time from when to calculate the statistics * @param startTimeUnit The unit of the start time * @param notifier The aggregating trimmer that produces the aggregated data */ public AggregatedSlidingWindowTimeReservoir( final long window, final TimeUnit windowUnit, final long startTime, final TimeUnit startTimeUnit, final AggregatingTrimmer notifier) { super(window, windowUnit, startTime, startTimeUnit); this.notifier = notifier; notifier.register(this); }