[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] advice precedence

I wanted to add to this thread that the rules stand for after / after
returning / after throwing advices ie that an after (finally) advice
can execute before an after throwing advice if it comes first in the
source code.

Alex


On Tue, 4 Jan 2005 14:30:29 +0000, Adrian Colyer
<adrian_colyer@xxxxxxxxxx> wrote:
> > Any insight for the use case of supporting that ?
> See my previous post in reply to Pope's message for that.
> 
> > From the rule you explain, it seems that actually the behavior is half
> > way that since "after" is having a special rule that means that we can
> > actually *never* have "after -> around".
> > So why "before" is not having a special rule as well ?
> 
> This isn't correct. If I have ordered source declarations (around, after),
> then according to rule 2, since "either" of the declarations is after
> advice, the precedence is:
> 
> after -> around
> 
> and you would see:
> ...
> hello
> around-exit
> after
> 
> With ordered source declarations (after, around), the precedence is:
> 
> around -> after
> 
> and you would see:
> 
> ...
> hello
> after
> around-exit
> 
> Regards, Adrian.
> 
> -- Adrian
> Adrian_Colyer@xxxxxxxxxx
> 
> Alexandre Vasseur <avasseur@xxxxxxxxx>
> Sent by: aspectj-users-admin@xxxxxxxxxxx
> 04/01/2005 13:43
> Please respond to
> aspectj-users@xxxxxxxxxxx
> 
> To
> aspectj-users@xxxxxxxxxxx
> cc
> 
> Subject
> Re: [aspectj-users] advice precedence
> 
> Thanks for the explanation.
> 
> Any insight for the use case of supporting that ?
> If I am right, I think the others that supports "before" (AspectWerkz,
> Spring AOP) are assuming that ALL "before" (even between different
> aspects no matter precedence of those) are all before the "around",
> etc
> 
> ie that advice kind precedence wins over user defined precedence.
> This allow to not have advice precedence circularity (only aspect
> precedence circularity).
> 
> From the rule you explain, it seems that actually the behavior is half
> way that since "after" is having a special rule that means that we can
> actually *never* have "after -> around".
> So why "before" is not having a special rule as well ?
> 
> How many of you are using this source code driven precedence ?
> I am suprised since I just discovered that when commenting /
> uncommenting some code in my aspects.
> 
> Further on, discussing with friends that had read both books (Manning
> and Wiley) it appeared that this fact was not clear to them neither.
> Ramnivas any comments ?
> 
> Alex
> 
> On Tue, 4 Jan 2005 13:18:03 +0000, Adrian Colyer
> <adrian_colyer@xxxxxxxxxx> wrote:
> > A good question to start the new year with :)
> >
> > > What is the rule for precedence between lets say a before, around and
> > > an after advice defined in one single aspect and affecting the same
> > > joinpoint ?
> >
> > > But when trying some with AJDT / AJ 1.2.0 on Eclipse 3.0.1 I have some
> > > results that depends on the source code order of my advices:
> >
> > As you quote from the user guide:
> >
> > > "If the two pieces of advice are defined in the same aspect, then
> > > there are two cases:
> > >     * If either are after advice, then the one that appears later in
> > > the aspect has precedence over the one that appears earlier.
> > >     * Otherwise, then the one that appears earlier in the aspect has
> > > precedence over the one that appears later. "
> >
> > On the "way in" to a join point, the advice with the highest precedence
> > executes first, and on the "way out" the advice with the highest
> > precedence executes last.
> >
> > Here "later in the aspect" means "later in the source file" - ie.
> exactly
> > that the order depends on the order of the advice declarations in the
> > source file.
> >
> > > "before, around, after" in source leads to
> > > before
> > > around -->
> > >   hello
> > > around --<
> > > after
> >
> > This order is derived as follows:
> >
> > given the pair (before, around) then by the second clause the one that
> > appears earlier in the source has precedence:
> >
> > before -> around
> >
> > given the pair(around, after) the by the first clause the after advice
> has
> > precedence so we get:
> >
> > after -> around
> >
> > on the "way in" the highest precedence goes first so we see "before,
> > around-entry" and on the way out the highest precedence goes last so we
> > see "around-exit, after". Giving:
> >
> > before
> > around-entry
> > hello
> > around-exit
> > after
> >
> > > "around, before, after" in source leads to
> > > around -->
> > > before
> > >   hello
> > > around --<
> > > after
> >
> > This order is derived as follows:
> >
> > given the pair (around, before) then by the second clause the one that
> > appears earlier in the source has precedence:
> >
> > around -> before
> >
> > given the pair (around, after) then by the first clause the after advice
> > has precedence:
> >
> > after -> around
> >
> > on the "way in" this gives us "around-entry, before" and on the
> "way-out"
> > this gives us "around-exit, after". Giving:
> >
> > around-entry
> > before
> > hello
> > around-exit
> > after
> >
> > > "before, after, around" in source leads to a compilation error that
> > > says "can't determine precedence between two or more pieces of advice
> > > that apply to the same join point: method-execution(void
> > >  preced.Preced.hello())"
> >
> > Applying the first rule to the pair (before, after) we see that the
> after
> > advice has precedence:
> >
> > after -> before
> >
> > Applying the first rule to the pair (after, around) we see that the
> around
> > advice has precedence:
> >
> > around -> after
> >
> > Applying the second rule to the pair (before, around), we see that the
> > before advice has precedence:
> >
> > before -> around
> >
> > If we put these together we get: around -> after -> before -> around ->
> > ...
> > In previous versions of AspectJ I recall this being reported as a
> > "circular precedence error" or some similar wording - but the error
> > message has subsequently been improved to give the one that you
> witnessed.
> >
> > -- Adrian
> > Adrian_Colyer@xxxxxxxxxx
> >
> > Alexandre Vasseur <avasseur@xxxxxxxxx>
> > Sent by: aspectj-users-admin@xxxxxxxxxxx
> > 03/01/2005 10:17
> > Please respond to
> > aspectj-users@xxxxxxxxxxx
> >
> > To
> > aspectj-users@xxxxxxxxxxx
> > cc
> >
> > Subject
> > [aspectj-users] advice precedence
> >
> >
> > Hi
> >
> > I discovered today that one of my assumption seems to be wrong.
> > What is the rule for precedence between lets say a before, around and
> > an after advice defined in one single aspect and affecting the same
> > joinpoint ?
> >
> > In both Manning and Wiley books on AspectJ, I understood that it would
> > happen like this:
> > "before, around, after".
> >
> > But when trying some with AJDT / AJ 1.2.0 on Eclipse 3.0.1 I have some
> > results that depends on the source code order of my advices:
> >
> > "before, around, after" in source leads to
> > before
> > around -->
> >   hello
> > around --<
> > after
> >
> > "around, before, after" in source leads to  [ see the before nested
> > within the around' proceed() ]
> > around -->
> > before
> >   hello
> > around --<
> > after
> >
> > "before, after, around" in source leads to a compilation error that
> > says "can't determine precedence between two or more pieces of advice
> > that apply to the same join point: method-execution(void
> >  preced.Preced.hello())"
> >
> > Reading the AspectJ Programming guide did not give me a clue except
> > perhaps:
> > "If the two pieces of advice are defined in the same aspect, then
> > there are two cases:
> >     * If either are after advice, then the one that appears later in
> > the aspect has precedence over the one that appears earlier.
> >     * Otherwise, then the one that appears earlier in the aspect has
> > precedence over the one that appears later. "
> >
> > Does that means that there is no implicit rule that say that a before
> > advice will execute before the around advice (as long as those are in
> > the same aspect).
> > Why the 3rd source order leads to a compilation error ?
> >
> > Below the little code snip
> > Alex
> >
> > package preced;
> > public class Preced {
> >
> >                  public void hello() {
> >                                  System.out.println("  hello");
> >                  }
> >
> >                  public static void main(String[] args) {
> >                                  (new Preced()).hello();
> >                  }
> >
> >                  static aspect MyAspect {
> >                                  before() : execution(* *Preced.hello())
> {
> >  System.out.println("before");
> >                                  }
> >                                  Object around() : execution(*
> > *Preced.hello()) {
> >  System.out.println("around -->");
> >                                                  proceed();
> >  System.out.println("around --<");
> >                                                  return null;
> >                                  }
> >                                  after() : execution(* *Preced.hello())
> {
> >  System.out.println("after");
> >                                  }
> >                  }
> > }
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
>