com.netflix.spectator.api.Utils.propagateTypeError()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(292)

本文整理了Java中com.netflix.spectator.api.Utils.propagateTypeError()方法的一些代码示例,展示了Utils.propagateTypeError()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.propagateTypeError()方法的具体详情如下:
包路径:com.netflix.spectator.api.Utils
类名称:Utils
方法名:propagateTypeError

Utils.propagateTypeError介绍

[英]Propagate a type error exception. Used in situations where an existing id has already been registered but with a different class.
[中]传播类型错误异常。用于现有id已注册但属于不同类别的情况。

代码示例

代码示例来源: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: 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;
}

代码示例来源: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

Object c = Utils.computeIfAbsent(state, id, i -> tuple);
if (!(c instanceof ValueState)) {
 Utils.propagateTypeError(registry, id, PolledMeter.class, c.getClass());
} else {
 ValueState<T> t = (ValueState<T>) c;

代码示例来源:origin: com.netflix.spectator/spectator-api

Object c = Utils.computeIfAbsent(state, id, i -> tuple);
if (!(c instanceof ValueState)) {
 Utils.propagateTypeError(registry, id, PolledMeter.class, c.getClass());
} else {
 ValueState<T> t = (ValueState<T>) c;

代码示例来源:origin: Netflix/spectator

Object c = Utils.computeIfAbsent(state, id, i -> tuple);
if (!(c instanceof CounterState)) {
 Utils.propagateTypeError(registry, id, PolledMeter.class, c.getClass());
} else {
 CounterState<T> t = (CounterState<T>) c;

代码示例来源:origin: com.netflix.spectator/spectator-api

Object c = Utils.computeIfAbsent(state, id, i -> tuple);
if (!(c instanceof CounterState)) {
 Utils.propagateTypeError(registry, id, PolledMeter.class, c.getClass());
} else {
 CounterState<T> t = (CounterState<T>) c;

代码示例来源:origin: com.netflix.spectator/spectator-api

/**
 * Creates a timer for tracking long running tasks.
 *
 * @param registry
 *     Registry to use.
 * @param id
 *     Identifier for the metric being registered.
 * @return
 *     Timer instance.
 */
public static LongTaskTimer get(Registry registry, Id id) {
 ConcurrentMap<Id, Object> state = registry.state();
 Object obj = Utils.computeIfAbsent(state, id, i -> {
  LongTaskTimer timer = new LongTaskTimer(registry, id);
  PolledMeter.using(registry)
    .withId(id)
    .withTag(Statistic.activeTasks)
    .monitorValue(timer, LongTaskTimer::activeTasks);
  PolledMeter.using(registry)
    .withId(id)
    .withTag(Statistic.duration)
    .monitorValue(timer, t -> t.duration() / NANOS_PER_SECOND);
  return timer;
 });
 if (!(obj instanceof LongTaskTimer)) {
  Utils.propagateTypeError(registry, id, LongTaskTimer.class, obj.getClass());
  obj = new LongTaskTimer(new NoopRegistry(), id);
 }
 return (LongTaskTimer) obj;
}

代码示例来源:origin: Netflix/spectator

/**
 * Creates a timer for tracking long running tasks.
 *
 * @param registry
 *     Registry to use.
 * @param id
 *     Identifier for the metric being registered.
 * @return
 *     Timer instance.
 */
public static LongTaskTimer get(Registry registry, Id id) {
 ConcurrentMap<Id, Object> state = registry.state();
 Object obj = Utils.computeIfAbsent(state, id, i -> {
  LongTaskTimer timer = new LongTaskTimer(registry, id);
  PolledMeter.using(registry)
    .withId(id)
    .withTag(Statistic.activeTasks)
    .monitorValue(timer, LongTaskTimer::activeTasks);
  PolledMeter.using(registry)
    .withId(id)
    .withTag(Statistic.duration)
    .monitorValue(timer, t -> t.duration() / NANOS_PER_SECOND);
  return timer;
 });
 if (!(obj instanceof LongTaskTimer)) {
  Utils.propagateTypeError(registry, id, LongTaskTimer.class, obj.getClass());
  obj = new LongTaskTimer(new NoopRegistry(), id);
 }
 return (LongTaskTimer) obj;
}

相关文章