Search in sources :

Example 1 with Counter

use of org.eclipse.microprofile.metrics.Counter in project Payara by payara.

the class CountedInterceptor method applyInterceptor.

@Override
protected <E extends Member & AnnotatedElement> Object applyInterceptor(InvocationContext context, E element) throws Exception {
    MetricsResolver.Of<Counted> counted = resolver.counted(bean.getBeanClass(), element);
    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();
        }
    }
}
Also used : Counted(org.eclipse.microprofile.metrics.annotation.Counted) Counter(org.eclipse.microprofile.metrics.Counter) MetricsResolver(fish.payara.microprofile.metrics.cdi.MetricsResolver)

Aggregations

MetricsResolver (fish.payara.microprofile.metrics.cdi.MetricsResolver)1 Counter (org.eclipse.microprofile.metrics.Counter)1 Counted (org.eclipse.microprofile.metrics.annotation.Counted)1