[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[aspectj-users] How to intercept proceed() in around() advice
- From: Alexander Kriegisch <Alexander@xxxxxxxxxxxxxx>
- Date: Sat, 25 Aug 2012 11:57:15 +0200
- Delivered-to: firstname.lastname@example.org
- Organization: Scrum-Master.de - Agiles Projektmanagement
- User-agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20120713 Thunderbird/14.0
I have asked this question on StackOverflow  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 , 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.