Monitors { static void addAnnotatedFields( List<Monitor<?>> monitors, String id, TagList tags, Object obj) { final Class<com.netflix.servo.annotations.Monitor> annoClass = com.netflix.servo.annotations.Monitor.class; try { Set<Field> fields = getFieldsAnnotatedBy(obj.getClass(), annoClass); for (Field field : fields) { final com.netflix.servo.annotations.Monitor anno = field.getAnnotation(annoClass); if (anno != null) { final MonitorConfig config = newConfig(obj.getClass(), field.getName(), id, anno, tags); if (anno.type() == DataSourceType.INFORMATIONAL) { monitors.add(new AnnotatedStringMonitor(config, obj, field)); } else { checkType(anno, field.getType(), field.getDeclaringClass()); monitors.add(new AnnotatedNumberMonitor(config, obj, field)); } } } Set<Method> methods = getMethodsAnnotatedBy(obj.getClass(), annoClass); for (Method method : methods) { final com.netflix.servo.annotations.Monitor anno = method.getAnnotation(annoClass); if (anno != null) { final MonitorConfig config = newConfig(obj.getClass(), method.getName(), id, anno, tags); if (anno.type() == DataSourceType.INFORMATIONAL) { monitors.add(new AnnotatedStringMonitor(config, obj, method)); } else { checkType(anno, method.getReturnType(), method.getDeclaringClass()); monitors.add(new AnnotatedNumberMonitor(config, obj, method)); } } } } catch (Exception e) { throw Throwables.propagate(e); } } private  Monitors(); static Timer newTimer(String name); static Timer newTimer(String name, TaggingContext context); static Timer newTimer(String name, TimeUnit unit); static Timer newTimer(String name, TimeUnit unit, TaggingContext context); static Counter newCounter(String name); static Counter newCounter(String name, TaggingContext context); static CompositeMonitor<?> newObjectMonitor(Object obj); static CompositeMonitor<?> newObjectMonitor(String id, Object obj); static CompositeMonitor<?> newThreadPoolMonitor(String id, ThreadPoolExecutor pool); static CompositeMonitor<?> newCacheMonitor(String id, Cache<?, ?> cache); static void registerObject(Object obj); static void unregisterObject(Object obj); static void unregisterObject(String id, Object obj); static void registerObject(String id, Object obj); static boolean isObjectRegistered(Object obj); static boolean isObjectRegistered(String id, Object obj);  }
@Test public void testAddAnnotatedFields() throws Exception { List<Monitor<?>> monitors = new ArrayList<>(); ClassWithMonitors obj = new ClassWithMonitors(); Monitors.addAnnotatedFields(monitors, null, null, obj); Monitors.addAnnotatedFields(monitors, "foo", null, obj); assertEquals(monitors.size(), 8); }