Hi,

I am working on a timer example using AspectJ similar to this logging
example:
http://adamgent.com/post/5479576926/the-python-decorator-pattern-for-java-using-aspectj

However the Timer (not Logger) I am using takes among others a String
argument which describes the context of the place where you are timing
(i.e. if you are timing a save method in a DAO class, the argument would be
"save"). Now that the Timer is defined in the Aspect, is it possible to
retrieve some context information outside of the pointcut or advice
definition? Ideally I want to do something like:

public aspect TimedAspect {

    private final Timer TIMER = Metrics.newTimer(getClass(), "TARGET METHOD
NAME HERE");

    pointcut timedExecution() : execution(@Timed * * (..)); // execution of
a annotated method

    Object around() : timedExecution() {
        final TimerContext context = TIMER.time();
        try {
            return proceed();
        } finally {
            context.stop();
        }
    }
}

For me it looks like the only way is to create the Timer object inside the
advice and use the context information available.
_______________________________________________
aspectj-users mailing list
aspectj-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to