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

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

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

Registry.methodValue介绍

[英]Tells the registry to regularly poll the object by by using reflection to invoke the named method and report the returned value as a gauge. The registration will keep a weak reference to the object so it will not prevent garbage collection. The registered method should be thread safe and cheap to invoke. Never perform any potentially long running or expensive activity such as IO inline. To get better compile time type safety, #gauge(Id,Object,ToDoubleFunction)should be preferred. Use this technique only if there access or other restrictions prevent using a proper function reference. However, keep in mind that makes your code more brittle and prone to failure in the future. For more information see #gauge(Id,Object,ToDoubleFunction).
[中]告诉注册表定期轮询对象,方法是使用反射来调用指定的方法,并将返回的值报告为度量值。注册将保留对对象的弱引用,因此不会阻止垃圾收集。注册的方法应该是线程安全的,并且调用成本低。永远不要执行任何潜在的长时间运行或昂贵的活动,如IO内联。为了获得更好的编译时类型安全性,应该首选#gauge(Id、Object、ToDoubleFunction)。只有在访问权限或其他限制阻止使用正确的函数引用时,才使用此技术。但是,请记住,这会使您的代码更脆弱,将来更容易失败。有关更多信息,请参见#仪表(Id、对象、ToDoubleFunction)。

代码示例

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

@Override
public void methodValue(String name, Object obj, String method) {
  composite.methodValue(name, obj, method);
}

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

@Override
public void methodValue(Id id, Object obj, String method) {
  composite.methodValue(id, obj, method);
}

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

/**
 * Tells the registry to regularly poll the object by by using reflection to invoke the named
 * method and report the returned value as a gauge. See {@link #methodValue(Id, Object, String)}
 * for more information.
 *
 * @param name
 *     Name of the metric being registered.
 * @param obj
 *     Object used to compute a value.
 * @param method
 *     Name of the method to invoke on the object.
 * @deprecated
 *     Use {@link PolledMeter} instead. This method has been deprecated to help
 *     reduce confusion between active gauges that are explicitly updated by the
 *     user and passive gauges that are polled in the background. Going forward
 *     the registry methods will only be used for the core types directly updated
 *     by the user. Other patterns such as {@link PolledMeter}s will be handled
 *     separately. Scheduled to be removed in 2.0.
 */
@Deprecated
default void methodValue(String name, Object obj, String method) {
 methodValue(createId(name), obj, method);
}

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

/**
 * Tells the registry to regularly poll the object by by using reflection to invoke the named
 * method and report the returned value as a gauge. See {@link #methodValue(Id, Object, String)}
 * for more information.
 *
 * @param name
 *     Name of the metric being registered.
 * @param obj
 *     Object used to compute a value.
 * @param method
 *     Name of the method to invoke on the object.
 * @deprecated
 *     Use {@link PolledMeter} instead. This method has been deprecated to help
 *     reduce confusion between active gauges that are explicitly updated by the
 *     user and passive gauges that are polled in the background. Going forward
 *     the registry methods will only be used for the core types directly updated
 *     by the user. Other patterns such as {@link PolledMeter}s will be handled
 *     separately. Scheduled to be removed in 2.0.
 */
@Deprecated
default void methodValue(String name, Object obj, String method) {
 methodValue(createId(name), obj, method);
}

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

@Test
public void methodValueUnknown() {
 Assertions.assertThrows(RuntimeException.class, () -> {
  Registry r = newRegistry(true, 10000);
  r.methodValue("queueSize", this, "unknownMethod");
 });
}

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

@Test
public void methodValueBadReturnType() {
 Assertions.assertThrows(ClassCastException.class, () -> {
  Registry r = newRegistry(true, 10000);
  r.methodValue("queueSize", this, "toString");
 });
}

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

@Test
public void testMethodValueHelpers() {
 Registry r = newRegistry(true, 10000);
 LinkedBlockingDeque<String> q1 = new LinkedBlockingDeque<>();
 r.methodValue("queueSize", q1, "size");
 Id id = r.createId("queueSize");
 assertGaugeValue(r, id, 0.0);
 q1.push("foo");
 assertGaugeValue(r, id, 1.0);
}

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

@Test
public void methodValueBadReturnTypeNoPropagate() {
 Registry r = newRegistry(false, 10000);
 r.methodValue("queueSize", this, "toString");
 Assertions.assertNull(r.get(r.createId("queueSize")));
}

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

@Test
public void methodValueUnknownNoPropagate() {
 Registry r = newRegistry(false, 10000);
 r.methodValue("queueSize", this, "unknownMethod");
 Assertions.assertNull(r.get(r.createId("queueSize")));
}

相关文章