Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Guidaance on Cflow usage

Ramnivas has already pointed out the !within(<aspect>) idiom you want to
use here.

I want to use Donal's message to bring up a couple of points that may be more
generally helpful.  His message raises some issues that I've heard several
times now, so it seemed worth trying to write down some of the answer.  

(Apologies to Donal for dumping all this in response to your message.
Since you're a teacher and a textbook developer I hope you'll forgive
me using your message to stress a general set of points!)

The two key points I want to make are that:

 - Join points, pointcuts and advice are orthogonal.
 - Advice are on pointcuts, and pointcuts match join points.

So an advice "knows" what pointcut it is on; and poincuts "know"
what join points they match. But there is relationship in the other
direction -- pointcuts don't know what advice is on them; join points
don't know what pointcuts match them, or what advice runs at them.

One consequence of this is that when you are trying to think about why
a particular advice is (or isn't) running, you can focus on the pointcut,
and what join points it matches. It doesn't matter about what kind of
advice it is.

It can also help sharpen other questions about pointcuts.

For example, in:

  Maybe cflow should match all join points during the execution,
  even if they are introduced by virtue of the same cflow call.

That description doesn't really fit the AspectJ model. There is no
such thing as a "cflow call".  All that is happening is that cflow is
matching a join point, and that join point just happens to arise because
of advice  on that pointcut. But the cflow part of the pointcut knows
nothing about the advice.

Similarly, in:

  If it is okay for advice statements of an aspect to match pointcuts
  in the same aspect, then I shouldn't have to use the mangled name to
  do it.

In the AspectJ model, advice statements don't match. Just pointcuts
do. And, as before, the orthogonality of the three concepts makes
how poincuts match join points independent of advice.


Finally, with regard to the details of matching advice execution join
points, the pointcut that does that is 'adviceexecution()'. I can't
remember whether we ever considered trying to have the execution pointcut
match advice execution join points.  adviceexecution came up pretty late,
so probably not.





> -----Original Message-----
> From: aspectj-users-admin@xxxxxxxxxxx 
> [mailto:aspectj-users-admin@xxxxxxxxxxx] On Behalf Of Donal Lafferty
> Sent: Sunday, August 17, 2003 1:35 PM
> To: aspectj-users@xxxxxxxxxxx
> Subject: RE: [aspectj-users] Guidaance on Cflow usage
> 
> 
> 1. Using cflowbelow does not help.  In the example provided, the
> pointcut argument of the cflow designator does not explicitly 
> match the
> advice in Cflow.aj.  So, using cflowbelow should result in the same
> behaviour, and I get the same behaviour when I modify the pointcut to
> use cflow instead of cflowbelow.
> 
> 2. Perhaps the behaviour I'm seeing is not a problem.  Maybe cflow
> should match all join points during the execution, even if they are
> introduced by virtue of the same cflow call.  In this light its okay
> that calls advice in Cflow.aj are caught.
> 
> 3.  If it is okay for advice statements of an aspect to match 
> pointcuts
> in the same aspect, then I shouldn't have to use the mangled 
> name to do
> it.  Should I?  If advice statements are legitimate join 
> points, then I
> would expect to be able to use execution designators to pick them out.
> In a way I can, ex. call( * *.*( * )) seems to select calls to the
> advice in cflow.aj.  However, given the claim that aspects 
> are modelled
> on Java types, I would expect that something like call( * 
> Cflow.*( * ))
> would also select advice from the aspect Cflow.  Unfortunately it does
> not.
> 
> 
> DL
> 
> 
> -----Original Message-----
> From: aspectj-users-admin@xxxxxxxxxxx
> [mailto:aspectj-users-admin@xxxxxxxxxxx] On Behalf Of Ramnivas Laddad
> Sent: 16 August 2003 20:08
> To: aspectj-users@xxxxxxxxxxx
> Subject: Re: [aspectj-users] Guidaance on Cflow usage
> 
> Donal,
> 
> You need to use cflowbelow() pointcut to exclude the join point
> itself. 
> 
> There is a sample chapter (chapter 3) from my book posted that 
> covers control-flow based pointcuts:
> http://www.manning.com/laddad/
> 
> -Ramnivas
> 
> --- Donal Lafferty <laffertd@xxxxxxxxx> wrote:
> > Hi!
> > 
> > I'm having trouble coming to grasps with cflow pointcuts.  In the
> > example below, I was surprised to find out that cflow advice is
> > included
> > in the set of cflow join points, which leads to an infinite
> > recursion.
> > Although I'm tempted to submit this as a bug, I'm not wholly
> > convinced I
> > understand what I'm doing.  Moreover, the bug submission system is
> > down.
> > 
> > Any comments on the problem are more than welcome!
> > 
> > Cheers,
> > 
> > 
> > DL
> > 
> > 
> > WordCounterDemo.java
> > 
> > class WordCounterDemo 
> > {
> >   static String[] smallSample= {"This", "demos", "infinite", "loop",
> > "in", 
> >                                  "cflow", "before", "advice"};
> > 
> >   public static void main(String[] args) {
> >     WordCounter wordCounter = new WordCounter();
> >     String word;
> >     String[] wordList1 = smallSample;
> >     int words = 0;
> >     for (int i = 0; i < wordList1.length; i++) {
> >       word = smallSample[i];
> >       System.out.println("Adding " + word +", as word #" + 
> > (++words));
> >       wordCounter.Add(word);
> >     }
> >   }
> > }
> > 
> > WordCounter.java
> > 
> > public class WordCounter {
> >   public void Add(String word) {
> >     System.out.println("Add entry, word = "+word.toString());
> >   }
> > }
> > 
> > Cflow.aj
> > 
> > public aspect Cflow {
> >   pointcut AddCflow():  cflow( execution( * WordCounter.Add( * )));
> > 
> >   // In AspectJ 1.0.6 and 1.1 here is an infinite loop here, because
> > the
> > 
> >   // before advice is itself considered a join point in the cflow.
> >   before(): AddCflow() { System.out.println("Before advice 
> call" ); }
> > }
> > 
> > CflowWeave.lst
> > 
> > WordCounterDemo.java
> > WordCounter.java
> > Cflow.aj
> > 
> > 
> > Which compiles with:
> > 
> > ajc -argfile CflowWeave.lst
> > 
> > And runs with:
> > 
> > java -classpatch "%CLASSPATH;./" WordCounterDemo
> > 
> > Gives the output
> > 
> > Adding This, as word#1
> > Exception in thread "main" java.langStackOverflowError
> > 
> > 
> > 
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
> http://sitebuilder.yahoo.com
> _______________________________________________
> 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
> 




Back to the top