@Counted(name = "countedConstructor", monotonic = true) public CountedConstructorBean() { } }
@Override protected Object invoke(MethodInvocation invocation, Counter counter, Counted annotation) throws Throwable { try { counter.inc(); return invocation.proceed(); } finally { if (!annotation.monotonic()) { counter.dec(); } } }
@Nonnull @Override public String getNameForCounted(@Nonnull Method method, @Nonnull Counted counted) { if (counted.absolute()) { return counted.name(); } if (counted.name().isEmpty()) { if (counted.monotonic()) { return name(method.getDeclaringClass(), method.getName(), COUNTER_SUFFIX_MONOTONIC); } else { return name(method.getDeclaringClass(), method.getName(), COUNTER_SUFFIX); } } return name(method.getDeclaringClass(), counted.name()); }
@Override public String getName(Counted annotation) { return annotation.name(); }
@Override public boolean isAbsoluteName(Counted annotation) { return annotation.absolute(); }
@Nonnull @Override public String getNameForCounted(@Nonnull Method method, @Nonnull Counted counted) { if (counted.absolute()) { return counted.name(); } if (counted.name().isEmpty()) { if (counted.monotonic()) { return name(method.getDeclaringClass(), method.getName(), COUNTER_SUFFIX_MONOTONIC); } else { return name(method.getDeclaringClass(), method.getName(), COUNTER_SUFFIX); } } return name(method.getDeclaringClass(), counted.name()); }
private String metricName(Annotation annotation) { if (CachedGauge.class.isInstance(annotation)) return ((CachedGauge) annotation).name(); else if (Counted.class.isInstance(annotation)) return ((Counted) annotation).name(); else if (ExceptionMetered.class.isInstance(annotation)) return ((ExceptionMetered) annotation).name(); else if (Gauge.class.isInstance(annotation)) return ((Gauge) annotation).name(); else if (Metered.class.isInstance(annotation)) return ((Metered) annotation).name(); else if (Timed.class.isInstance(annotation)) return ((Timed) annotation).name(); else throw new IllegalArgumentException("Unsupported Metrics forMethod [" + annotation.getClass().getName() + "]"); }
private boolean isMetricAbsolute(Annotation annotation) { if (extension.<Boolean>getParameter(UseAbsoluteName).orElse(false)) return true; if (CachedGauge.class.isInstance(annotation)) return ((CachedGauge) annotation).absolute(); else if (Counted.class.isInstance(annotation)) return ((Counted) annotation).absolute(); else if (ExceptionMetered.class.isInstance(annotation)) return ((ExceptionMetered) annotation).absolute(); else if (Gauge.class.isInstance(annotation)) return ((Gauge) annotation).absolute(); else if (Metered.class.isInstance(annotation)) return ((Metered) annotation).absolute(); else if (Timed.class.isInstance(annotation)) return ((Timed) annotation).absolute(); else throw new IllegalArgumentException("Unsupported Metrics forMethod [" + annotation.getClass().getName() + "]"); }
@Counted(name = "countedClass") public class CountedClassBean { public void countedMethodOne() { } public void countedMethodTwo() { } protected void countedMethodProtected() { } void countedMethodPackagedPrivate() { } private void countedMethodPrivate() { } }
private String metricName(Annotation annotation) { if (CachedGauge.class.isInstance(annotation)) return ((CachedGauge) annotation).name(); else if (Counted.class.isInstance(annotation)) return ((Counted) annotation).name(); else if (ExceptionMetered.class.isInstance(annotation)) return ((ExceptionMetered) annotation).name(); else if (Gauge.class.isInstance(annotation)) return ((Gauge) annotation).name(); else if (Metered.class.isInstance(annotation)) return ((Metered) annotation).name(); else if (Timed.class.isInstance(annotation)) return ((Timed) annotation).name(); else throw new IllegalArgumentException("Unsupported Metrics forMethod [" + annotation.getClass().getName() + "]"); }
private boolean isMetricAbsolute(Annotation annotation) { if (extension.<Boolean>getParameter(UseAbsoluteName).orElse(false)) return true; if (CachedGauge.class.isInstance(annotation)) return ((CachedGauge) annotation).absolute(); else if (Counted.class.isInstance(annotation)) return ((Counted) annotation).absolute(); else if (ExceptionMetered.class.isInstance(annotation)) return ((ExceptionMetered) annotation).absolute(); else if (Gauge.class.isInstance(annotation)) return ((Gauge) annotation).absolute(); else if (Metered.class.isInstance(annotation)) return ((Metered) annotation).absolute(); else if (Timed.class.isInstance(annotation)) return ((Timed) annotation).absolute(); else throw new IllegalArgumentException("Unsupported Metrics forMethod [" + annotation.getClass().getName() + "]"); }
CountedInterceptor(Counter counter, Counted annotation) { this.counter = counter; decrementAfterMethod = !annotation.monotonic(); }
@Counted(name = "monotonicCountedClass", monotonic = true) public class MonotonicCountedClassBean { public void countedMethodOne() { } public void countedMethodTwo() { } protected void countedMethodProtected() { } void countedMethodPackagedPrivate() { } private void countedMethodPrivate() { } }
CountedInterceptor(Counter counter, Counted annotation) { this.counter = counter; decrementAfterMethod = !annotation.monotonic(); }
@Counted public void defaultNameCountedMethod() { }
private Object countedCallable(InvocationContext context, Executable executable) throws Exception { MetricResolver.Of<Counted> counted = resolver.counted(bean.getBeanClass(), executable); Counter counter = (Counter) registry.getMetrics().get(counted.metricName()); if (counter == null) throw new IllegalStateException("No counter with name [" + counted.metricName() + "] found in registry [" + registry + "]"); counter.inc(); try { return context.proceed(); } finally { if (!counted.metricAnnotation().monotonic()) counter.dec(); } } }
@Counted(absolute = true) public void absoluteDefaultNameCountedMethod() { }
private Object countedCallable(InvocationContext context, Executable executable) throws Exception { MetricResolver.Of<Counted> counted = resolver.counted(bean.getBeanClass(), executable); Counter counter = (Counter) registry.getMetrics().get(counted.metricName()); if (counter == null) throw new IllegalStateException("No counter with name [" + counted.metricName() + "] found in registry [" + registry + "]"); counter.inc(); try { return context.proceed(); } finally { if (!counted.metricAnnotation().monotonic()) counter.dec(); } } }