Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Newbie Question: Aspect behaviour?

> Do I need to do something more involved like "de-registering" a pointcut
> from some kind of list kept by the system if I don't need it any more?

There is nothing too complex here.  It is doing as you asked, you need
to remember that there are two methods called count in the system.
Test01.count() and CountUtils.count() - both which take String,String
and return an int.  You didn't say which one you wanted (your first
pointcut specifies Test01 but your new pointcut doesnt say which one
it is interested in).

So you are seeing the before/after applying to the call to
Test01.count() and then the same advice applying to the call that
method makes to CountUtils.count.

cheers,
Andy

On 24 February 2012 15:11, Rhino <rhino1@xxxxxxxxxxxx> wrote:
> This is the second of my newbie questions about AspectJ. See "Newbie
> Questions: Biggest Issue" for the previous one....
>
> My next question is about some odd behaviour I got when I added a second
> pointcut that would have involved the same method of my play program. (The
> previous email contains the full contents of the play program.)
>
> When I had this as my aspect:
>
> ====================================================
>
> package test;
>
> public aspect LogCount {
>
>    pointcut howManyNeedles() : execution(* Test01.count(..));
>
> //    pointcut howManyNeedles2() : call(int count(String, String));
>
>    /* First Before */
>    before() : howManyNeedles() {
>        System.out.println("About to count...."); //$NON-NLS-1$
>    }
>
>    /* First After */
>    after() returning() : howManyNeedles() {
>        System.out.println("...Needles counted");  //$NON-NLS-1$
>    }
>
> }
>
>
>
> =====================================================
>
> The "About to count...." and "...Needles counted" lines got printed once
> each as expected.
>
> Then I changed the code by commenting out pointcut howManyNeedles() and
> creating a pointcut howManyNeedles2(). Then I changed all incidents of
> howManyNeedles() to howManyNeedles2() in the "before" and "after" so that
> the code looked like this::
>
> =======================================================
> package test;
>
> public aspect LogCount {
>
> //    pointcut howManyNeedles() : execution(* Test01.count(..));
>
>    pointcut howManyNeedles2() : call(int count(String, String));
>
>    /* First Before */
>    before() : howManyNeedles2() {
>        System.out.println("About to count...."); //$NON-NLS-1$
>    }
>
>    /* First After */
>    after() returning() : howManyNeedles2() {
>        System.out.println("...Needles counted");  //$NON-NLS-1$
>    }
>
> }
> =======================================================
>
> Much to my surprise, I got "About to count..." TWICE, followed by
> "...Needles counted", also twice.
>
> Why did that happen? I would have thought I'd get those two lines once each
> since howManyNeedles() was now commented out but it still seemed to be in
> effect despite that.
>
> Do I need to do something more involved like "de-registering" a pointcut
> from some kind of list kept by the system if I don't need it any more?
>
> --
> Rhino
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top