下面列出了com.google.common.collect.EvictingQueue#create ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public KafkaIngestionHealthCheck(Config config, KafkaExtractorStatsTracker statsTracker) {
this.config = config;
this.slidingWindowSize = ConfigUtils.getInt(config, KAFKA_INGESTION_HEALTH_CHECK_SLIDING_WINDOW_SIZE_KEY, DEFAULT_KAFKA_INGESTION_HEALTH_CHECK_SLIDING_WINDOW_SIZE);
this.ingestionLatencyThresholdMinutes = ConfigUtils.getLong(config, KAFKA_INGESTION_HEALTH_CHECK_LATENCY_THRESHOLD_MINUTES_KEY, DEFAULT_KAFKA_INGESTION_HEALTH_CHECK_LATENCY_THRESHOLD_MINUTES);
this.consumptionRateDropOffFraction = ConfigUtils.getDouble(config, KAFKA_INGESTION_HEALTH_CHECK_CONSUMPTION_RATE_DROPOFF_FRACTION_KEY, DEFAULT_KAFKA_INGESTION_HEALTH_CHECK_CONSUMPTION_RATE_DROPOFF_FRACTION);
this.expectedConsumptionRate = ConfigUtils.getDouble(config, KAFKA_INGESTION_HEALTH_CHECK_EXPECTED_CONSUMPTION_RATE_MBPS_KEY, DEFAULT_KAFKA_INGESTION_HEALTH_CHECK_EXPECTED_CONSUMPTION_RATE_MBPS);
this.increasingLatencyCheckEnabled = ConfigUtils.getBoolean(config, KAFKA_INGESTION_HEALTH_CHECK_INCREASING_LATENCY_CHECK_ENABLED_KEY, DEFAULT_KAFKA_INGESTION_HEALTH_CHECK_INCREASING_LATENCY_CHECK_ENABLED);
this.ingestionLatencies = EvictingQueue.create(this.slidingWindowSize);
this.consumptionRateMBps = EvictingQueue.create(this.slidingWindowSize);
EventBus eventBus;
try {
eventBus = EventBusFactory.get(ContainerHealthCheckFailureEvent.CONTAINER_HEALTH_CHECK_EVENT_BUS_NAME,
SharedResourcesBrokerFactory.getImplicitBroker());
} catch (IOException e) {
log.error("Could not find EventBus instance for container health check", e);
eventBus = null;
}
this.eventBus = eventBus;
this.statsTracker = statsTracker;
}
public ProducerBatch(
GroupKey groupKey,
String packageId,
int batchSizeThresholdInBytes,
int batchCountThreshold,
int maxReservedAttempts,
long nowMs) {
this.groupKey = groupKey;
this.packageId = packageId;
this.createdMs = nowMs;
this.batchSizeThresholdInBytes = batchSizeThresholdInBytes;
this.batchCountThreshold = batchCountThreshold;
this.curBatchCount = 0;
this.curBatchSizeInBytes = 0;
this.reservedAttempts = EvictingQueue.create(maxReservedAttempts);
this.attemptCount = 0;
}
private ArimaProcess(Builder builder) {
this.coefficients = builder.coefficients;
this.distribution = builder.distribution;
this.period = builder.period;
this.seasonalCycle = builder.seasonalCycle;
this.startTime = builder.startTime;
this.currentTime = startTime;
int seasonalFrequency = (int) builder.period.frequencyPer(builder.seasonalCycle);
double[] arSarCoeffs = ArimaCoefficients.expandArCoefficients(coefficients.arCoeffs(),
coefficients.seasonalARCoeffs(),
seasonalFrequency);
double[] maSmaCoeffs = ArimaCoefficients.expandMaCoefficients(coefficients.maCoeffs(),
coefficients.seasonalMACoeffs(),
seasonalFrequency);
this.errors = EvictingQueue.create(maSmaCoeffs.length);
this.diffSeries = EvictingQueue.create(arSarCoeffs.length);
this.series = EvictingQueue.create(coefficients.d() + coefficients.D() * seasonalFrequency);
this.maPoly = LagPolynomial.movingAverage(maSmaCoeffs);
this.arPoly = LagPolynomial.autoRegressive(arSarCoeffs);
this.diffPoly = LagPolynomial.differences(coefficients.d())
.times(LagPolynomial.seasonalDifferences(seasonalFrequency, coefficients.D()));
}
public void resend(String endpointId) {
Queue<DelayedMessage> delayedMessages = delayedMessageRegistry.remove(endpointId);
if (delayedMessages == null || delayedMessages.isEmpty()) {
return;
}
Optional<Session> sessionOptional = registry.get(endpointId);
if (!sessionOptional.isPresent()) {
return;
}
Queue<DelayedMessage> backingQueue = EvictingQueue.create(delayedMessages.size());
while (!delayedMessages.isEmpty()) {
backingQueue.offer(delayedMessages.poll());
}
Session session = sessionOptional.get();
for (DelayedMessage delayedMessage : backingQueue) {
if (session.isOpen()) {
session.getAsyncRemote().sendText(delayedMessage.message);
} else {
delayedMessages.add(delayedMessage);
}
}
if (!delayedMessages.isEmpty()) {
delayedMessageRegistry.put(endpointId, delayedMessages);
}
}
public PendingTransactions(
final int maxTransactionRetentionHours,
final int maxPendingTransactions,
final int maxPooledTransactionHashes,
final Clock clock,
final MetricsSystem metricsSystem,
final Supplier<BlockHeader> chainHeadHeaderSupplier,
final Optional<EIP1559> eip1559,
final Percentage priceBump) {
this.maxTransactionRetentionHours = maxTransactionRetentionHours;
this.maxPendingTransactions = maxPendingTransactions;
this.clock = clock;
this.newPooledHashes = EvictingQueue.create(maxPooledTransactionHashes);
this.chainHeadHeaderSupplier = chainHeadHeaderSupplier;
this.transactionReplacementHandler = new TransactionPoolReplacementHandler(eip1559, priceBump);
final LabelledMetric<Counter> transactionAddedCounter =
metricsSystem.createLabelledCounter(
BesuMetricCategory.TRANSACTION_POOL,
"transactions_added_total",
"Count of transactions added to the transaction pool",
"source");
localTransactionAddedCounter = transactionAddedCounter.labels("local");
remoteTransactionAddedCounter = transactionAddedCounter.labels("remote");
localTransactionHashesAddedCounter = transactionAddedCounter.labels("pool");
transactionRemovedCounter =
metricsSystem.createLabelledCounter(
BesuMetricCategory.TRANSACTION_POOL,
"transactions_removed_total",
"Count of transactions removed from the transaction pool",
"source",
"operation");
}
public SmaPointForecaster(SmaPointForecasterParams params) {
notNull(params, "params can't be null");
params.validate();
this.params = params;
this.periodOfValues = EvictingQueue.create(params.getLookBackPeriod());
if (params.getInitialPeriodOfValues() != null) {
params.getInitialPeriodOfValues().forEach(this::updateMeanEstimate);
}
}
public EdmxDetector(UUID uuid, EdmxHyperparams hyperparams, boolean trusted) {
notNull(uuid, "uuid can't be null");
notNull(hyperparams, "hyperparams can't be null");
hyperparams.validate();
log.info("Creating EdmxDetector: uuid={}, hyperparams={}", uuid, hyperparams);
this.uuid = uuid;
this.hyperparams = hyperparams;
this.buffer = EvictingQueue.create(hyperparams.getBufferSize());
this.trusted = trusted;
}
public SimpleFileTailer(File file) {
this.file = file;
this.history = EvictingQueue.create(2500);
this.inbuf = new byte[8192 * 8];
try {
this.randomAccessFile = new RandomAccessFile(file, "r");
} catch (FileNotFoundException e) {
throw new RuntimeException(Utils.format("Unexpected error reading output file '{}': {}", file, e), e);
}
}
public BoostVHTActiveLearningNode(double[] classObservation, int parallelism_hint, SplittingOption splitOption, int maxBufferSize) {
super(classObservation, parallelism_hint);
weightSeenAtLastSplitEvaluation = this.getWeightSeen();
id = VerticalHoeffdingTree.LearningNodeIdGenerator.generate();
attributeContentEventKeys = new HashMap<>();
isSplitting = false;
parallelismHint = parallelism_hint;
this.splittingOption = splitOption;
this.maxBufferSize = maxBufferSize;
this.buffer = EvictingQueue.create(maxBufferSize);
}
public OfferOutcomeSummary() {
this.acceptedCount = 0;
this.rejectedCount = 0;
this.outcomes = EvictingQueue.create(DEFAULT_CAPACITY);
this.failureReasons = new HashMap<>();
this.rejectedAgents = new HashMap<>();
}
TimeSeriesImpl(String name) {
this.name = name;
samples = EvictingQueue.create(retainedSampleLimit);
}
@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);
}
TraceEvents(int maxNumEvents) {
events = EvictingQueue.create(maxNumEvents);
}
private Bucket(int numSamples) {
sampledSpansQueue = EvictingQueue.create(numSamples);
notSampledSpansQueue = EvictingQueue.create(numSamples);
}
private QueueMetricProducer(int bufferSize) {
synchronized (monitor) {
bufferedMetrics = EvictingQueue.<Metric>create(bufferSize);
}
}
@Override
public EvictingQueue<InstanceCommunication.FunctionStatus.ExceptionInformation> getLatestSinkExceptions() {
return EvictingQueue.create(0);
}
/**
* LRUQueue, 如果Queue已满,则删除最旧的元素.
*
* 内部实现是ArrayDeque
*/
public static <E> EvictingQueue<E> createLRUQueue(int maxSize) {
return EvictingQueue.create(maxSize);
}
/**
* Creates a new instance with specified capacity.
*
* @param capacity the size of the underlying ring buffer.
*/
public MessageTrace(final int capacity) {
traceEntries = EvictingQueue.create(capacity);
this.capacity = capacity;
}
/**
* Creates a new instance with specified capacity.
*
* @param capacity the size of the underlying ring buffer.
*/
public OnHeapRingBufferMessageStore(final int capacity) {
this.entries = EvictingQueue.create(capacity);
}
/**
* LRUQueue, 如果Queue已满,则删除最旧的元素.
*
* 内部实现是ArrayDeque
*/
public static <E> EvictingQueue<E> createLRUQueue(int maxSize) {
return EvictingQueue.create(maxSize);
}