Java Code Examples for com.google.common.collect.EvictingQueue#peek()

The following examples show how to use com.google.common.collect.EvictingQueue#peek() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PaperTimingsCommand.java    From LagMonitor with MIT License 6 votes vote down vote up
@Override
protected void sendTimings(CommandSender sender) {
    EvictingQueue<TimingHistory> history = Reflection.getField(TimingsManager.class, "HISTORY", EvictingQueue.class)
            .get(null);

    TimingHistory lastHistory = history.peek();
    if (lastHistory == null) {
        sendError(sender, "Not enough data collected yet");
        return;
    }

    List<BaseComponent[]> lines = new ArrayList<>();
    printTimings(lines, lastHistory);

    Pages pagination = new Pages("Paper Timings", lines);
    pagination.send(sender);

    plugin.getPageManager().setPagination(sender.getName(), pagination);
}
 
Example 2
Source File: PaperTimingsCommand.java    From LagMonitor with MIT License 6 votes vote down vote up
@Override
protected void sendTimings(CommandSender sender) {
    EvictingQueue<TimingHistory> history = Reflection.getField(TimingsManager.class, "HISTORY", EvictingQueue.class)
            .get(null);

    TimingHistory lastHistory = history.peek();
    if (lastHistory == null) {
        sendError(sender, "Not enough data collected yet");
        return;
    }

    List<BaseComponent[]> lines = new ArrayList<>();
    printTimings(lines, lastHistory);

    Pages pagination = new Pages("Paper Timings", lines);
    pagination.send(sender);

    plugin.getPageManager().setPagination(sender.getName(), pagination);
}
 
Example 3
Source File: SerialDiffPipelineAggregator.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public InternalAggregation reduce(InternalAggregation aggregation, ReduceContext reduceContext) {
    InternalHistogram histo = (InternalHistogram) aggregation;
    List<? extends InternalHistogram.Bucket> buckets = histo.getBuckets();
    InternalHistogram.Factory<? extends InternalHistogram.Bucket> factory = histo.getFactory();

    List newBuckets = new ArrayList<>();
    EvictingQueue<Double> lagWindow = EvictingQueue.create(lag);
    int counter = 0;

    for (InternalHistogram.Bucket bucket : buckets) {
        Double thisBucketValue = resolveBucketValue(histo, bucket, bucketsPaths()[0], gapPolicy);
        InternalHistogram.Bucket newBucket = bucket;

        counter += 1;

        // Still under the initial lag period, add nothing and move on
        Double lagValue;
        if (counter <= lag) {
            lagValue = Double.NaN;
        } else {
            lagValue = lagWindow.peek();  // Peek here, because we rely on add'ing to always move the window
        }

        // Normalize null's to NaN
        if (thisBucketValue == null) {
            thisBucketValue = Double.NaN;
        }

        // Both have values, calculate diff and replace the "empty" bucket
        if (!Double.isNaN(thisBucketValue) && !Double.isNaN(lagValue)) {
            double diff = thisBucketValue - lagValue;

            List<InternalAggregation> aggs = new ArrayList<>(eagerTransform(bucket.getAggregations().asList(), AGGREGATION_TRANFORM_FUNCTION));
            aggs.add(new InternalSimpleValue(name(), diff, formatter, new ArrayList<PipelineAggregator>(), metaData()));
            newBucket = factory.createBucket(bucket.getKey(), bucket.getDocCount(), new InternalAggregations(
                    aggs), bucket.getKeyed(), bucket.getFormatter());
        }


        newBuckets.add(newBucket);
        lagWindow.add(thisBucketValue);

    }
    return factory.create(newBuckets, histo);
}