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

x33g5p2x  于2022-01-28 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(90)

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

Registry.state介绍

[英]Returns a map that can be used to associate state with the registry. Users instrumenting their application will most likely never need to use this method. The primary use case is for building custom meter types that need some additional state beyond the core types supported by the registry. This map can be used to store the state so that the lifecycle of the data is connected to the registry. For an example, see some of the built in patterns such as com.netflix.spectator.api.patterns.LongTaskTimer.
[中]返回可用于将状态与注册表关联的映射。检测应用程序的用户很可能永远不需要使用这种方法。主要用例用于构建自定义仪表类型,这些仪表类型需要在注册表支持的核心类型之外的一些附加状态。此映射可用于存储状态,以便将数据的生命周期连接到注册表。例如,请参阅一些内置模式,例如com。netflix。观众应用程序编程接口。模式。LongTaskTimer。

代码示例

代码示例来源:origin: org.springframework.metrics/spring-metrics

@Override
public ConcurrentMap<Id, Object> state() {
  return composite.state();
}

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

@Override public ConcurrentMap<Id, Object> state() {
 return impl.state();
}

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

@Override public ConcurrentMap<Id, Object> state() {
 return impl.state();
}

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

/**
 * Explicitly disable polling for the meter registered with {@code id}. This is optional
 * and is mostly used if it is desirable for the meter to go away immediately. The polling
 * will stop automatically when the referred object is garbage collected. See
 * {@link Builder#monitorValue(Object, ToDoubleFunction)} for more information.
 */
public static void remove(Registry registry, Id id) {
 Object obj = registry.state().get(id);
 if (obj instanceof AbstractMeterState) {
  registry.state().remove(id, obj);
 }
}

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

/**
 * Explicitly disable polling for the meter registered with {@code id}. This is optional
 * and is mostly used if it is desirable for the meter to go away immediately. The polling
 * will stop automatically when the referred object is garbage collected. See
 * {@link Builder#monitorValue(Object, ToDoubleFunction)} for more information.
 */
public static void remove(Registry registry, Id id) {
 Object obj = registry.state().get(id);
 if (obj instanceof AbstractMeterState) {
  registry.state().remove(id, obj);
 }
}

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

/** Force the polling of all meters associated with the registry. */
public static void update(Registry registry) {
 Iterator<Map.Entry<Id, Object>> iter = registry.state().entrySet().iterator();
 while (iter.hasNext()) {
  Map.Entry<Id, Object> entry = iter.next();
  if (entry.getValue() instanceof AbstractMeterState) {
   AbstractMeterState tuple = (AbstractMeterState) entry.getValue();
   tuple.doUpdate(registry);
   if (tuple.hasExpired()) {
    iter.remove();
   }
  }
 }
}

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

/** Force the polling of all meters associated with the registry. */
public static void update(Registry registry) {
 Iterator<Map.Entry<Id, Object>> iter = registry.state().entrySet().iterator();
 while (iter.hasNext()) {
  Map.Entry<Id, Object> entry = iter.next();
  if (entry.getValue() instanceof AbstractMeterState) {
   AbstractMeterState tuple = (AbstractMeterState) entry.getValue();
   tuple.doUpdate(registry);
   if (tuple.hasExpired()) {
    iter.remove();
   }
  }
 }
}

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

/**
 * Update the registry if this meter is not expired, otherwise cleanup any state
 * associated with this meter.
 */
@SuppressWarnings("PMD.AvoidCatchingThrowable")
void doUpdate(Registry registry) {
 if (hasExpired()) {
  registry.state().remove(id());
 } else {
  try {
   update(registry);
  } catch (Throwable t) {
   LOGGER.trace("uncaught exception from gauge function for [{}]", id(), t);
   throw t;
  }
 }
}

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

/**
 * Update the registry if this meter is not expired, otherwise cleanup any state
 * associated with this meter.
 */
@SuppressWarnings("PMD.AvoidCatchingThrowable")
void doUpdate(Registry registry) {
 if (hasExpired()) {
  registry.state().remove(id());
 } else {
  try {
   update(registry);
  } catch (Throwable t) {
   LOGGER.trace("uncaught exception from gauge function for [{}]", id(), t);
   throw t;
  }
 }
}

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

@Test
 public void removeOtherType() throws Exception {
  LongTaskTimer t = LongTaskTimer.get(registry, id);
  Assertions.assertEquals(3, registry.state().size());
  PolledMeter.remove(registry, id);
  Assertions.assertEquals(3, registry.state().size());
 }
}

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

@Test
public void expire() throws Exception {
 WeakReference<LongAdder> ref = new WeakReference<>(
  PolledMeter.using(registry).withId(id).monitorMonotonicCounter(new LongAdder()));
 while (ref.get() != null) {
  System.gc();
 }
 Assertions.assertEquals(1, registry.state().size());
 update();
 Assertions.assertEquals(0, registry.state().size());
}

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

final ValueState<T> tuple = new ValueState<>(gauge);
ConcurrentMap<Id, Object> state = registry.state();
Object c = Utils.computeIfAbsent(state, id, i -> tuple);
if (!(c instanceof ValueState)) {

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

final ValueState<T> tuple = new ValueState<>(gauge);
ConcurrentMap<Id, Object> state = registry.state();
Object c = Utils.computeIfAbsent(state, id, i -> tuple);
if (!(c instanceof ValueState)) {

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

@Test
public void removeGauge() throws Exception {
 LongAdder v = PolledMeter.using(registry).withId(id).monitorMonotonicCounter(new LongAdder());
 Assertions.assertEquals(1, registry.state().size());
 PolledMeter.remove(registry, id);
 Assertions.assertEquals(0, registry.state().size());
}

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

相关文章