[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] How to intercept proceed() in around() advice

I have asked this question on StackOverflow [1] before, but received no
answer so far. Maybe somebody here has one for me:

Because it is impossible to bind a constant or dynamic parameter to an
advice in a pointcut [2], I have a bunch of logging around() advice A
which set a message to be logged (ThreadLocal private member of aspect)
and then call proceed(). I would like to be able to intercept the
proceed() in any of those advice from another advice B which does the
actual logging and indentation work so as to avoid code duplication in
the other advice, but there is no joinpoint available to do that. I
verified this by logging *all* joinpoints within those advice.

What I came up with is a rather complicated combination of
  - intercepting the set() operations on the internal variable
    containing the log message in an after() advice, doing indentation
    and pre-proceed() logging there, and
  - Java annotation tags on the many advice A plus another after()
    advice capturing the end of each advice A, doing dedentation
    and post-proceed() logging there.

If anyone is interested I can post real or pseudo code, but I just
wanted to explain *why* I need an interceptable joinpoint on proceed()
if I do not want to use any tricks or trade one type of code repetition
(the logging/indentation calls) for another (chaining all logging
pointcuts used on advice of type A like "a() || b() || c() || ...",
repeating them and having to update them if I add another logging
pointcut + advice.

Attention: I *cannot* just use another around() advice intercepting the
other adviceexecution()s because I need to wait until the log message
has been constructed inside of them. That would not be a problem either
if I could intercept proceed() and would have the additional advantage
that after proceed() I could even do other things in the advice, e.g.
log more info not captured by the one-line message logged by my
hypothetical advice B.

I hope that all of this was understandable. Otherwise, please ask.

Bottom line: My wish is a pointcut "proceedexecution()" or similar.

[1]
http://stackoverflow.com/questions/12018585/how-to-intercept-proceed-in-another-aspectj-aspect
[2] https://bugs.eclipse.org/bugs/show_bug.cgi?id=92889
-- 
Alexander Kriegisch