protected void withMethod(final Object bean, String beanName, Class<?> targetClass, final Method method) {
if (method.getParameterTypes().length > 0) {
throw new IllegalStateException("Method " + method.getName() + " is annotated with @CachedGauge but requires parameters.");
}
final CachedGauge annotation = method.getAnnotation(CachedGauge.class);
final String metricName = Util.forCachedGauge(targetClass, method, annotation);
metrics.register(metricName, new com.codahale.metrics.CachedGauge<Object>(annotation.timeout(), annotation.timeoutUnit()) {
@Override
protected Object loadValue() {
return ReflectionUtils.invokeMethod(method, bean);
}
});