本文整理了Java中com.netflix.spectator.api.Utils.computeIfAbsent()
方法的一些代码示例,展示了Utils.computeIfAbsent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.computeIfAbsent()
方法的具体详情如下:
包路径:com.netflix.spectator.api.Utils
类名称:Utils
方法名:computeIfAbsent
[英]This method should be used instead of the ConcurrentMap#computeIfAbsent(Object,Function) call to minimize thread contention. This method does not require locking for the common case where the key exists, but potentially performs additional computation when absent.
[中]应该使用此方法,而不是ConcurrentMap#ComputeFabSent(对象、函数)调用,以最小化线程争用。对于存在密钥的常见情况,此方法不需要锁定,但在缺少密钥时可能会执行额外的计算。
代码示例来源:origin: Netflix/spectator
/** Return the number of inflight requests associated with the given id. */
AtomicInteger inflightRequests(Id id) {
return Utils.computeIfAbsent(inflightRequests, id, i -> new AtomicInteger());
}
代码示例来源:origin: com.netflix.spectator/spectator-ext-ipc
/** Return the number of inflight requests associated with the given id. */
AtomicInteger inflightRequests(Id id) {
return Utils.computeIfAbsent(inflightRequests, id, i -> new AtomicInteger());
}
代码示例来源:origin: Netflix/spectator
/**
* Return the cardinality limiter for a given key. This is used to protect the metrics
* backend from a metrics explosion if some dimensions have a high cardinality.
*/
Function<String, String> limiterForKey(String key) {
return Utils.computeIfAbsent(limiters, key, k -> CardinalityLimiters.mostFrequent(10));
}
代码示例来源:origin: Netflix/spectator
@Override public String apply(String s) {
AtomicLong count = Utils.computeIfAbsent(values, s, k -> new AtomicLong(0L));
long num = count.incrementAndGet();
if (num >= cutoff) {
updateCutoff();
// cutoff may have been updated, double check it would still make the cut
String v = limiter.apply(s);
return num >= cutoff ? v : OTHERS;
} else {
return OTHERS;
}
}
代码示例来源:origin: com.netflix.spectator/spectator-api
@Override public String apply(String s) {
AtomicLong count = Utils.computeIfAbsent(values, s, k -> new AtomicLong(0L));
long num = count.incrementAndGet();
if (num >= cutoff) {
updateCutoff();
// cutoff may have been updated, double check it would still make the cut
String v = limiter.apply(s);
return num >= cutoff ? v : OTHERS;
} else {
return OTHERS;
}
}
代码示例来源:origin: com.netflix.spectator/spectator-ext-ipc
/**
* Return the cardinality limiter for a given key. This is used to protect the metrics
* backend from a metrics explosion if some dimensions have a high cardinality.
*/
Function<String, String> limiterForKey(String key) {
return Utils.computeIfAbsent(limiters, key, k -> CardinalityLimiters.mostFrequent(10));
}
代码示例来源:origin: Netflix/spectator
@Override public DistributionSummary distributionSummary(Id id) {
return Utils.computeIfAbsent(distSummaries, id,
i -> new SwapDistributionSummary(this, i, newDistributionSummary(i)));
}
代码示例来源:origin: Netflix/spectator
@Override public Gauge gauge(Id id) {
return Utils.computeIfAbsent(gauges, id, i -> new SwapGauge(this, i, newGauge(i)));
}
代码示例来源:origin: com.netflix.spectator/spectator-api
@Override public Timer timer(Id id) {
return Utils.computeIfAbsent(timers, id, i -> new SwapTimer(this, i, newTimer(i)));
}
代码示例来源:origin: Netflix/spectator
@Override public Counter counter(Id id) {
return Utils.computeIfAbsent(counters, id, i -> new SwapCounter(this, i, newCounter(i)));
}
代码示例来源:origin: Netflix/spectator
@Override public Gauge maxGauge(Id id) {
return Utils.computeIfAbsent(gauges, id, i -> new SwapGauge(this, i, newMaxGauge(i)));
}
代码示例来源:origin: Netflix/spectator
@Override public Timer timer(Id id) {
return Utils.computeIfAbsent(timers, id, i -> new SwapTimer(this, i, newTimer(i)));
}
代码示例来源:origin: com.netflix.spectator/spectator-api
@Override public DistributionSummary distributionSummary(Id id) {
return Utils.computeIfAbsent(distSummaries, id,
i -> new SwapDistributionSummary(this, i, newDistributionSummary(i)));
}
代码示例来源:origin: com.netflix.spectator/spectator-api
@Override public Gauge gauge(Id id) {
return Utils.computeIfAbsent(gauges, id, i -> new SwapGauge(this, i, newGauge(i)));
}
代码示例来源:origin: com.netflix.spectator/spectator-api
@Override public Counter counter(Id id) {
return Utils.computeIfAbsent(counters, id, i -> new SwapCounter(this, i, newCounter(i)));
}
代码示例来源:origin: com.netflix.spectator/spectator-api
@Override public Gauge maxGauge(Id id) {
return Utils.computeIfAbsent(gauges, id, i -> new SwapGauge(this, i, newMaxGauge(i)));
}
代码示例来源:origin: Netflix/spectator
/**
* Provided for backwards compatibility to support the {@link Registry#register(Meter)}
* method. Use the builder created with {@link #using(Registry)} instead.
*
* @deprecated This method only exists to allow for backwards compatibility and should
* be considered an internal detail. Scheduled to be removed in 2.0.
*/
@Deprecated
public static void monitorMeter(Registry registry, Meter meter) {
ConcurrentMap<Id, Object> state = registry.state();
Object c = Utils.computeIfAbsent(state, meter.id(), MeterState::new);
if (!(c instanceof MeterState)) {
Utils.propagateTypeError(registry, meter.id(), MeterState.class, c.getClass());
} else {
MeterState t = (MeterState) c;
t.add(meter);
long delay = registry.config().gaugePollingFrequency().toMillis();
t.schedule(registry, null, delay);
}
}
代码示例来源:origin: com.netflix.spectator/spectator-api
/**
* Provided for backwards compatibility to support the {@link Registry#register(Meter)}
* method. Use the builder created with {@link #using(Registry)} instead.
*
* @deprecated This method only exists to allow for backwards compatibility and should
* be considered an internal detail. Scheduled to be removed in 2.0.
*/
@Deprecated
public static void monitorMeter(Registry registry, Meter meter) {
ConcurrentMap<Id, Object> state = registry.state();
Object c = Utils.computeIfAbsent(state, meter.id(), MeterState::new);
if (!(c instanceof MeterState)) {
Utils.propagateTypeError(registry, meter.id(), MeterState.class, c.getClass());
} else {
MeterState t = (MeterState) c;
t.add(meter);
long delay = registry.config().gaugePollingFrequency().toMillis();
t.schedule(registry, null, delay);
}
}
代码示例来源:origin: com.netflix.spectator/spectator-api
/**
* Create a new instance.
*
* @param registry
* Registry to use.
* @param id
* Identifier for the metric being registered.
* @return
* Counter instance.
*/
public static IntervalCounter get(Registry registry, Id id) {
ConcurrentMap<Id, Object> state = registry.state();
Object c = Utils.computeIfAbsent(state, id, i -> new IntervalCounter(registry, i));
if (!(c instanceof IntervalCounter)) {
Utils.propagateTypeError(registry, id, IntervalCounter.class, c.getClass());
c = new IntervalCounter(new NoopRegistry(), id);
}
return (IntervalCounter) c;
}
代码示例来源:origin: Netflix/spectator
/**
* Create a new instance.
*
* @param registry
* Registry to use.
* @param id
* Identifier for the metric being registered.
* @return
* Counter instance.
*/
public static IntervalCounter get(Registry registry, Id id) {
ConcurrentMap<Id, Object> state = registry.state();
Object c = Utils.computeIfAbsent(state, id, i -> new IntervalCounter(registry, i));
if (!(c instanceof IntervalCounter)) {
Utils.propagateTypeError(registry, id, IntervalCounter.class, c.getClass());
c = new IntervalCounter(new NoopRegistry(), id);
}
return (IntervalCounter) c;
}
内容来源于网络,如有侵权,请联系作者删除!