Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] 1 pointcut, 2 around advice, Each advice calls code which is woven

Not sure if this will solve Kevin's problem.  According to what he
said earlier: "The code in each around advice calls code which is
woven by these very aspects.
Both advices call proceed() and return an Object."

So, this means that in Andy's solution, the advice in aspect One, will
have calls to AnInterface.  The executions of these calls will be
advised by advice in aspect Two, which I believe is not what is
desired.

I have 3 potential solutions, but none of which seem satisfying to me:

Solution 1: combine the two advice and keep the same pointcuts.  Not
very nice from a modularity point of view, but simple.

Solution 2: try to convert one of the advices from around to before
and after.  And ensure that the precedence order makes the before and
after run on either side of the around  (this would only work if the
outer advice won't need to return a different Object).

Solution 3: Simulate your own form of cflow.  Use Andy's suggestion
below, but also have a flag in each concrete aspect that can be set so
that the advice in the other aspect will not run when not desired.
Something like this:

(This version seems like a gross violation of separation of concerns,
the exact thing that AJ is trying to help with)

aspect One {
   void around(): execution(* foo(..)) && !cflow(adviceexecution() &&
within(One)) {
       if (otherFlagIsSet())  proceed();
       setMyFlag();
       // do stuff with AnInterface
       System.out.println("one");
       proceed();
       // do stuff with AnInterface
       unsetMyFlag();
   }
}

Perhaps someone else can come up with a better solution.

--a

On Fri, Mar 20, 2009 at 9:25 AM, Andy Clement <andrew.clement@xxxxxxxxx> wrote:
> Expand the pointcut to say which adviceexecution() join points you don't
> want to be in the cflow of
>
> aspect One {
>    void around(): execution(* foo(..)) && !cflow(adviceexecution() &&
> within(One)) {
>        System.out.println("one");
>        proceed();
>    }
> }
>
> aspect Two {
>        void around(): execution(* foo(..)) && !cflow(adviceexecution()&&
> within(Two)) {
>            System.out.println("two");
>            proceed();
>        }
>  }
>
> these worked for me.  Without with within() components I only see one of the
> advice run.
>
> Andy.
>
>
> 2009/3/20 Kevin Shale <shale@xxxxxx>
>>
>> Hi again,
>>
>> I am currently using the AJDT 1.6.3 plugin on Eclipse 1.3.4.
>>
>> I have an aj project containing 3 aspects and two around() advices for the
>> same pointcut.
>> 2 concrete aspects derive from an abstract aspect which defines this
>> common pointcut.
>> Each concrete aspect implements a different concern with an around()
>> advice.
>> The code in each around advice calls code which is woven by these very
>> aspects.
>> Both advices call proceed() and return an Object.
>>
>> My problem is that depending on the precedence order, only one of the two
>> advices manifests itself (it's the highest order one).
>>
>> For example, in the abstract aspect I declare the common pointcut:
>> protected pointcut myPointcut() : execution(* InterfaceA+.*(..)) &&
>> !cflow(adviceexecution());
>>
>> In the first aspect I advise by calling code which implements InterfaceA:
>> Object around() : myPointcut() {
>> // Code which executes methods in InterfaceA (which get woven by this very
>> advice)
>> Object result = proceed();
>> // More code which executes methods in InterfaceA (which get woven by this
>> very advice)
>> return result;
>> }
>>
>> The second aspect is more or less the same (it also calls woven code).
>> I suspect the !cflow(adviceexecution) - while preventing recursion - also
>> prevents the other lower order aspect from running.
>> Does anyone have a suggestion on how to best rewrite myPointcut?
>>
>> Thanks so much!
>> Kevin
>> _______________________________________________
>> aspectj-users mailing list
>> aspectj-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


Back to the top