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

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

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

Utils.getMethod介绍

[英]Search for a method in the class and all superclasses.
[中]在类和所有超类中搜索一个方法。

代码示例

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

/** Return a method supplying a value for a gauge. */
static Method getGaugeMethod(Registry registry, Id id, Object obj, String method) {
 try {
  final Method m = Utils.getMethod(obj.getClass(), method);
  try {
   // Make sure we can cast the response to a Number
   final Number n = (Number) m.invoke(obj);
   REGISTRY_LOGGER.debug(
     "registering gauge {}, using method [{}], with initial value {}", id, m, n);
   return m;
  } catch (Exception e) {
   final String msg = "exception thrown invoking method [" + m
     + "], skipping registration of gauge " + id;
   registry.propagate(msg, e);
  }
 } catch (NoSuchMethodException e) {
  final String mname = obj.getClass().getName() + "." + method;
  final String msg = "invalid method [" + mname + "], skipping registration of gauge " + id;
  registry.propagate(msg, e);
 }
 return null;
}

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

/** Return a method supplying a value for a gauge. */
static Method getGaugeMethod(Registry registry, Id id, Object obj, String method) {
 try {
  final Method m = Utils.getMethod(obj.getClass(), method);
  try {
   // Make sure we can cast the response to a Number
   final Number n = (Number) m.invoke(obj);
   REGISTRY_LOGGER.debug(
     "registering gauge {}, using method [{}], with initial value {}", id, m, n);
   return m;
  } catch (Exception e) {
   final String msg = "exception thrown invoking method [" + m
     + "], skipping registration of gauge " + id;
   registry.propagate(msg, e);
  }
 } catch (NoSuchMethodException e) {
  final String mname = obj.getClass().getName() + "." + method;
  final String msg = "invalid method [" + mname + "], skipping registration of gauge " + id;
  registry.propagate(msg, e);
 }
 return null;
}

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

@Test
public void invokeNoSuchMethod() throws Exception  {
 Assertions.assertThrows(NoSuchMethodException.class,
   () -> Functions.invokeMethod(Utils.getMethod(getClass(), "unknownMethod")));
}

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

@Test
public void invokeMethodInt() throws Exception  {
 final ToDoubleFunction<FunctionsTest> f = Functions.invokeMethod(Utils.getMethod(getClass(), "intMethod"));
 Assertions.assertEquals(f.applyAsDouble(this), 3.0, 1e-12);
}

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

@Test
public void invokeMethodLong() throws Exception  {
 final ToDoubleFunction<FunctionsTest> f = Functions.invokeMethod(Utils.getMethod(getClass(), "longMethod"));
 Assertions.assertEquals(f.applyAsDouble(this), 4.0, 1e-12);
}

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

@Test
public void invokeMethodWrapperLong() throws Exception  {
 final ToDoubleFunction<FunctionsTest> f = Functions.invokeMethod(
   Utils.getMethod(getClass(), "wrapperLongMethod"));
 Assertions.assertEquals(f.applyAsDouble(this), 5.0, 1e-12);
}

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

@Test
public void invokeMethodByte() throws Exception {
 final ToDoubleFunction<FunctionsTest> f = Functions.invokeMethod(Utils.getMethod(getClass(), "byteMethod"));
 Assertions.assertEquals(f.applyAsDouble(this), 1.0, 1e-12);
}

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

@Test
public void invokeMethodShort() throws Exception  {
 final ToDoubleFunction<FunctionsTest> f = Functions.invokeMethod(Utils.getMethod(getClass(), "shortMethod"));
 Assertions.assertEquals(f.applyAsDouble(this), 2.0, 1e-12);
}

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

@Test
public void invokeBadMethod() throws Exception  {
 final ToDoubleFunction<FunctionsTest> f = Functions.invokeMethod(Utils.getMethod(getClass(), "throwsMethod"));
 Assertions.assertEquals(f.applyAsDouble(this), Double.NaN, 1e-12);
}

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

@Test
public void invokeOneB() throws Exception  {
 final ToDoubleFunction<B> f = Functions.invokeMethod(Utils.getMethod(B.class, "one"));
 Assertions.assertEquals(f.applyAsDouble(new B()), -1.0, 1e-12);
}

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

@Test
public void invokeOneA() throws Exception  {
 final ToDoubleFunction<A> f = Functions.invokeMethod(Utils.getMethod(A.class, "one"));
 Assertions.assertEquals(f.applyAsDouble(new A()), 1.0, 1e-12);
}

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

@Test
public void invokeOnSubclass() throws Exception  {
 final ToDoubleFunction<B> f = Functions.invokeMethod(Utils.getMethod(B.class, "two"));
 Assertions.assertEquals(f.applyAsDouble(new B()), 2.0, 1e-12);
}

相关文章