package com.acme.structure;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

import org.apache.log4j.Logger;

public class PerformanceMonitor
{
    private Logger logger = Logger.getLogger(this.getClass());

    @AroundInvoke
    public Object calculateProfile(InvocationContext invocation) throws Exception
    {
        long startTime = System.currentTimeMillis();
        try
        {
            return invocation.proceed();
        }
        finally
        {
            long endTime = System.currentTimeMillis() - startTime;
            logger.debug("Method " + invocation.getMethod() + " took " + endTime + " (ms)");
            //System.out.println("Method " + invocation.getMethod() + " took " + endTime + " (ms)");
        }
    }
}
