@Override public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { if (method.getParameterTypes().length > 0) { throw new IllegalStateException("Method " + method.getName() + " is annotated with @Gauge but requires parameters."); } final Gauge gauge = method.getAnnotation(Gauge.class); final String group = MetricName.chooseGroup(gauge.group(), targetClass); final String type = MetricName.chooseType(gauge.type(), targetClass); final String name = MetricName.chooseName(gauge.name(), method); final MetricName metricName = new MetricName(group, type, name, scope); metrics.newGauge(metricName, new GaugeMethod(bean, method)); if (log.isDebugEnabled()) { log.debug("Created gauge " + metricName + " for method " + targetClass.getCanonicalName() + "." + method.getName()); } } }, filter);
@Override public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { final Metered metered = method.getAnnotation(Metered.class); final String group = MetricName.chooseGroup(metered.group(), targetClass); final String type = MetricName.chooseType(metered.type(), targetClass); final String name = MetricName.chooseName(metered.name(), method); final MetricName metricName = new MetricName(group, type, name, scope); final Meter meter = metrics.newMeter(metricName, metered.eventType(), metered.rateUnit()); meters.put(method.getName(), meter); if (log.isDebugEnabled()) { log.debug("Created metric " + metricName + " for method " + method.getName()); } }
@Override public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { final Timed timed = method.getAnnotation(Timed.class); final String group = MetricName.chooseGroup(timed.group(), targetClass); final String type = MetricName.chooseType(timed.type(), targetClass); final String name = MetricName.chooseName(timed.name(), method); final MetricName metricName = new MetricName(group, type, name, scope); final Timer timer = metrics.newTimer(metricName, timed.durationUnit(), timed.rateUnit()); timers.put(method.getName(), timer); if (log.isDebugEnabled()) { log.debug("Created metric " + metricName + " for method " + method.getName()); } }
@Override public <I> void hear(final TypeLiteral<I> literal, TypeEncounter<I> encounter) { for (final Method method : literal.getRawType().getMethods()) { final Gauge annotation = method.getAnnotation(Gauge.class); if (annotation != null) { if (method.getParameterTypes().length == 0) { final String group = MetricName.chooseGroup(annotation.group(), literal.getRawType()); final String type = MetricName.chooseType(annotation.type(), literal.getRawType()); final String name = MetricName.chooseName(annotation.name(), method); final MetricName metricName = new MetricName(group, type, name); encounter.register(new GaugeInjectionListener<I>(metricsRegistry, metricName, method)); } else { encounter.addError("Method %s is annotated with @Gauge but requires parameters.", method); } } } }
static MethodInterceptor forMethod(MetricsRegistry metricsRegistry, Class<?> klass, Method method) { final Timed annotation = method.getAnnotation(Timed.class); if (annotation != null) { final String group = MetricName.chooseGroup(annotation.group(), klass); final String type = MetricName.chooseType(annotation.type(), klass); final String name = MetricName.chooseName(annotation.name(), method); final MetricName metricName = new MetricName(group, type, name); final Timer timer = metricsRegistry.newTimer(metricName, annotation.durationUnit(), annotation.rateUnit()); return new TimedInterceptor(timer); } return null; }
static MethodInterceptor forMethod(MetricsRegistry metricsRegistry, Class<?> klass, Method method) { final Metered annotation = method.getAnnotation(Metered.class); if (annotation != null) { final String group = MetricName.chooseGroup(annotation.group(), klass); final String type = MetricName.chooseType(annotation.type(), klass); final String name = MetricName.chooseName(annotation.name(), method); final MetricName metricName = new MetricName(group, type, name); final Meter meter = metricsRegistry.newMeter(metricName, annotation.eventType(), annotation.rateUnit()); return new MeteredInterceptor(meter); } return null; }
final String group = MetricName.chooseGroup(annotation.group(), klass); final String type = MetricName.chooseType(annotation.type(), klass); final String name = MetricName.chooseName(annotation.name(), method.getMethod()); final MetricName metricName = new MetricName(group, type, name); final String group = MetricName.chooseGroup(annotation.group(), klass); final String type = MetricName.chooseType(annotation.type(), klass); final String name = MetricName.chooseName(annotation.name(), method.getMethod()); final MetricName metricName = new MetricName(group, type, name);