All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.palominolabs.metrics.guice.CountedInterceptor Maven / Gradle / Ivy

There is a newer version: 0.40.13
Show newest version
package com.palominolabs.metrics.guice;

import com.codahale.metrics.Counter;
import com.codahale.metrics.annotation.Counted;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

class CountedInterceptor implements MethodInterceptor {

    private final Counter counter;
    private final boolean decrementAfterMethod;

    CountedInterceptor(Counter counter, Counted annotation) {
        this.counter = counter;
        decrementAfterMethod = !annotation.monotonic();
    }

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        counter.inc();
        try {
            return invocation.proceed();
        } finally {
            if (decrementAfterMethod) {
                counter.dec();
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy