List of usage examples for com.google.common.collect EvictingQueue create
public static <E> EvictingQueue<E> create(int maxSize)
From source file:com.arpnetworking.tsdcore.sinks.HttpSinkActor.java
/** * Public constructor./*from w w w . ja v a 2 s .com*/ * * @param client Http client to create requests from. * @param sink Sink that controls request creation and data serialization. * @param maximumConcurrency Maximum number of concurrent requests. * @param maximumQueueSize Maximum number of pending requests. * @param spreadPeriod Maximum time to delay sending new aggregates to spread load. */ public HttpSinkActor(final AsyncHttpClient client, final HttpPostSink sink, final int maximumConcurrency, final int maximumQueueSize, final Period spreadPeriod) { _client = client; _sink = sink; _maximumConcurrency = maximumConcurrency; _pendingRequests = EvictingQueue.create(maximumQueueSize); if (Period.ZERO.equals(spreadPeriod)) { _spreadingDelayMillis = 0; } else { _spreadingDelayMillis = new Random().nextInt((int) spreadPeriod.toStandardDuration().getMillis()); } }
From source file:org.hawkular.datamining.forecast.models.DoubleExponentialSmoothing.java
private DoubleExponentialSmoothing(double levelSmoothing, double trendSmoothing, MetricContext metricContext) { super(metricContext); if (levelSmoothing < MIN_LEVEL_TREND_SMOOTHING || levelSmoothing > MAX_LEVEL_TREND_SMOOTHING) { throw new IllegalArgumentException("Level parameter should be in interval 0-1"); }/*www . ja v a 2s . c o m*/ if (trendSmoothing < MIN_LEVEL_TREND_SMOOTHING || trendSmoothing > MAX_LEVEL_TREND_SMOOTHING) { throw new IllegalArgumentException("Trend parameter should be in 0-1"); } this.levelSmoothing = levelSmoothing; this.trendSmoothing = trendSmoothing; this.residuals = EvictingQueue.create(50); }
From source file:org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel.java
/** * Predicts the next `n` values in the series, using the smoothing model to generate new values. * Default prediction mode is to simply continuing calling <code>next()</code> and adding the * predicted value back into the windowed buffer. * * @param values Collection of numerics to movingAvg, usually windowed * @param numPredictions Number of newly generated predictions to return * @param <T> Type of numeric * @return Returns an array of doubles, since most smoothing methods operate on floating points *//*from w w w . j av a 2 s.c o m*/ public <T extends Number> double[] predict(Collection<T> values, int numPredictions) { double[] predictions = new double[numPredictions]; // If there are no values, we can't do anything. Return an array of NaNs. if (values.size() == 0) { return emptyPredictions(numPredictions); } // special case for one prediction, avoids allocation if (numPredictions < 1) { throw new IllegalArgumentException("numPredictions may not be less than 1."); } else if (numPredictions == 1) { predictions[0] = next(values); return predictions; } Collection<Number> predictionBuffer = EvictingQueue.create(values.size()); predictionBuffer.addAll(values); for (int i = 0; i < numPredictions; i++) { predictions[i] = next(predictionBuffer); // Add the last value to the buffer, so we can keep predicting predictionBuffer.add(predictions[i]); } return predictions; }
From source file:org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregator.java
@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;//from w ww. j a v a 2 s .c o m // 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<>( Lists.transform(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); }
From source file:com.android.build.gradle.integration.common.fixture.Logcat.java
private synchronized void start(@NonNull IDevice device, @Nullable final LogCatFilter filter) { mLogCatMessages = EvictingQueue.create(400); mFilteredLogCatMessages = Lists.newArrayList(); mLogCatReceiverTask = new LogCatReceiverTask(device); mLogCatReceiverTask.addLogCatListener(new LogCatListener() { @Override/*from ww w . ja va2s.c om*/ public void log(List<LogCatMessage> msgList) { for (LogCatMessage message : msgList) { mLogCatMessages.add(message); if (filter == null || filter.matches(message)) { mFilteredLogCatMessages.add(message); } } } }); mThread = new Thread(mLogCatReceiverTask); mThread.setDaemon(true); mThread.start(); }
From source file:org.apache.jackrabbit.oak.plugins.document.secondary.SecondaryStoreCache.java
public SecondaryStoreCache(NodeStore nodeStore, NodeStateDiffer differ, PathFilter pathFilter, StatisticsProvider statisticsProvider) { this.differ = differ; this.store = nodeStore; this.pathFilter = pathFilter; this.unknownPaths = statisticsProvider.getMeter("DOCUMENT_CACHE_SEC_UNKNOWN", StatsOptions.DEFAULT); this.knownMissed = statisticsProvider.getMeter("DOCUMENT_CACHE_SEC_KNOWN_MISSED", StatsOptions.DEFAULT); this.knownMissedOld = statisticsProvider.getMeter("DOCUMENT_CACHE_SEC_KNOWN_MISSED_OLD", StatsOptions.DEFAULT);/* w ww. j av a2 s. c o m*/ this.knownMissedNew = statisticsProvider.getMeter("DOCUMENT_CACHE_SEC_KNOWN_MISSED_NEW", StatsOptions.DEFAULT); this.knownMissedInRange = statisticsProvider.getMeter("DOCUMENT_CACHE_SEC_KNOWN_MISSED_IN_RANGE", StatsOptions.DEFAULT); this.headRevMatched = statisticsProvider.getMeter("DOCUMENT_CACHE_SEC_HEAD", StatsOptions.DEFAULT); this.prevRevMatched = statisticsProvider.getMeter("DOCUMENT_CACHE_SEC_OLD", StatsOptions.DEFAULT); this.queue = EvictingQueue.create(maxSize); }
From source file:org.owasp.webgoat.plugin.StoredXssComments.java
@RequestMapping(method = RequestMethod.POST) @ResponseBody//w ww. j a v a 2 s . c om public AttackResult createNewComment(@RequestBody String commentStr) throws IOException { Comment comment = parseJson(commentStr); EvictingQueue<Comment> comments = userComments.getOrDefault(webSession.getUserName(), EvictingQueue.create(100)); comment.setDateTime(DateTime.now().toString(fmt)); comment.setUser(webSession.getUserName()); comments.add(comment); userComments.put(webSession.getUserName(), comments); if (comment.getText().contains(phoneHomeString)) { return (success().feedback("xss-stored-comment-success").build()); } else { return (failed().feedback("xss-stored-comment-failure").build()); } }
From source file:org.lizardirc.beancounter.commands.sed.SedListener.java
public SedListener(ExecutorService executorService, int windowSize) { windows = CacheBuilder.newBuilder().build(CacheLoader.from(() -> EvictingQueue.create(windowSize))); this.executorService = executorService; }
From source file:org.apache.aurora.common.stats.TimeSeriesRepositoryImpl.java
@Inject public TimeSeriesRepositoryImpl(StatRegistry statRegistry, @Named(SAMPLE_PERIOD) Amount<Long, Time> samplePeriod, @Named(SAMPLE_RETENTION_PERIOD) final Amount<Long, Time> retentionPeriod, BuildInfo buildInfo) { this.statRegistry = checkNotNull(statRegistry); this.samplePeriod = checkNotNull(samplePeriod); this.buildInfo = checkNotNull(buildInfo); Preconditions.checkArgument(samplePeriod.getValue() > 0, "Sample period must be positive."); checkNotNull(retentionPeriod);/*from w w w . ja va 2 s . co m*/ Preconditions.checkArgument(retentionPeriod.getValue() > 0, "Sample retention period must be positive."); retainedSampleLimit = (int) (retentionPeriod.as(Time.SECONDS) / samplePeriod.as(Time.SECONDS)); Preconditions.checkArgument(retainedSampleLimit > 0, "Sample retention period must be greater than sample period."); timeSeries = CacheBuilder.newBuilder().build(new CacheLoader<String, TimeSeriesImpl>() { @Override public TimeSeriesImpl load(final String name) { TimeSeriesImpl timeSeries = new TimeSeriesImpl(name); // Backfill so we have data for pre-accumulated timestamps. int numTimestamps = timestamps.size(); if (numTimestamps != 0) { for (int i = 1; i < numTimestamps; i++) { timeSeries.addSample(0L); } } return timeSeries; } }); timestamps = EvictingQueue.create(retainedSampleLimit); }
From source file:org.hawkular.datamining.forecast.models.TripleExponentialSmoothing.java
private TripleExponentialSmoothing(int periods, double levelSmoothing, double trendSmoothing, double seasonalSmoothing, MetricContext metricContext) { super(metricContext); if (levelSmoothing < MIN_LEVEL_SMOOTHING || levelSmoothing > MAX_LEVEL_SMOOTHING) { throw new IllegalArgumentException("Level smoothing should be in interval 0-1"); }/* w ww . j a v a 2 s .c o m*/ if (trendSmoothing < MIN_TREND_SMOOTHING || trendSmoothing > MAX_TREND_SMOOTHING) { throw new IllegalArgumentException("Trend smoothing should be in 0-1"); } if (seasonalSmoothing < MIN_SEASONAL_SMOOTHING || seasonalSmoothing > MAX_SEASONAL_SMOOTHING) { throw new IllegalArgumentException("Seasonal smoothing should be in 0-1"); } if (periods < 2) { throw new IllegalArgumentException("Periods < 2, use non seasonal model."); } this.periods = periods; this.levelSmoothing = levelSmoothing; this.trendSmoothing = trendSmoothing; this.seasonalSmoothing = seasonalSmoothing; this.residuals = new EvictingQueue[this.periods]; for (int i = 0; i < residuals.length; i++) { this.residuals[i] = EvictingQueue.create(50); } }