
de.mcs.jmeasurement.spring.MeasureMethodInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JMeasurement Show documentation
Show all versions of JMeasurement Show documentation
JMeasurement profiling programs in production enviroment
The newest version!
/**
*
*/
package de.mcs.jmeasurement.spring;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import de.mcs.jmeasurement.JMConfig;
import de.mcs.jmeasurement.MeasureFactory;
import de.mcs.jmeasurement.Monitor;
/**
* This is the interceptor class to be used with spring aop feature.
*
* @author w.klaas
*/
public class MeasureMethodInterceptor implements MethodInterceptor {
/**
* This method will be invoked every time a method must be invoked with the aop advice.
*
* @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
*/
public Object invoke(MethodInvocation invocation) throws Throwable {
Object result = null;
StringBuffer name = new StringBuffer();
name.append(invocation.getMethod().getDeclaringClass().getCanonicalName());
name.append('#');
name.append(invocation.getMethod().getName());
if (MeasureFactory.getConfig().getBoolean(JMConfig.OPTION_POINT_NAME_WITH_PARAMETER)) {
for (Object arg : invocation.getArguments()) {
name.append('.');
if (arg != null) {
name.append(arg.toString());
}
}
}
Monitor monitor = MeasureFactory.start(name.toString());
result = invocation.proceed();
monitor.stop();
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy