Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Question about matching JoinPoints

Hi,

The call pointcut identifies a real method call in the code, but the
only way you can simulate a call once you have the joinpoint is via
reflection (well, I suppose you could generate a class that made the
call, but that is a bit over the top) - and reflective calls do not
look like real calls to AspectJ, they look like invocations of the
reflection API.  This is why I suggested using execution() because
then you will catch the method running regardless of the route taken
to get to it (regular call or reflection).

You could put a call pointcut on Method.invoke() and then pick apart
the arguments (this, target) to see what it is calling, but it won't
be caught by your regular call pointcuts.

In theory AspectJ could be extended to offer a runtime matching system
that would re-invoke any relevant advice, but that seems a lot of
work.

cheers,
Andy

On 23 November 2011 09:00, Andres Barrera <andres397@xxxxxxxxx> wrote:
> Thank you very much Andy, I did it and it's working just fine. But still I
> was wondering why it doesn´t work with the pointcut call? and where could I
> work to find a solution in the future?
> thanks,
> On Wed, Nov 16, 2011 at 11:24 AM, Andy Clement <andrew.clement@xxxxxxxxx>
> wrote:
>>
>> I don't have the time right now to create a fully fleshed out example,
>> but grabbing the method from the joinpoint object is where to start:
>>
>> MethodSignature ms =
>> (MethodSignature)thisJoinPointStaticPart.getSignature();
>> ms.getMethod().invoke();
>>
>> Andy
>>
>> On 13 November 2011 17:44, Andres Barrera <andres397@xxxxxxxxx> wrote:
>> > I think I can try it. Could you please explain me with some code how to
>> > do
>> > that? thank you
>> >
>> > On Sat, Nov 12, 2011 at 10:46 PM, Andy Clement
>> > <andrew.clement@xxxxxxxxx>
>> > wrote:
>> >>
>> >> Hi,
>> >>
>> >> AspectJ doesn't really support that kind of thing.
>> >>
>> >> If the pointcut you want to 'catch it again' can be an execution
>> >> pointcut, you could feasibly use reflection to invoke the joinpoint
>> >> again from your method (thisJoinPoint contains everything you need to
>> >> invoke it), then when it runs again the advice will fire again.
>> >>
>> >> Andy
>> >>
>> >> On 12 November 2011 12:19, Andres Barrera <andres397@xxxxxxxxx> wrote:
>> >> > Ok, what I mean is that, for example, I have some pointcuts and
>> >> > advices
>> >> > in
>> >> > an aspect, but also I have a method that receives a JoinPoint object.
>> >> > I
>> >> > need
>> >> > to declare a new Pointcut with that JoinPoint object, inside the
>> >> > method,
>> >> > so
>> >> > an advice can catch it. Its something like this:
>> >> > public aspect a1
>> >> > {
>> >> > pointcut p1(): call(* Class.method(*));
>> >> > before(): p1()
>> >> > {
>> >> > System.out.println("Inside the advice");
>> >> > method(thisJoinPoint);
>> >> > }
>> >> > public static void method(JoinPoint join)
>> >> > {
>> >> > //Evaluate it or match it, so advice can catch it again
>> >> > }
>> >> > }
>> >> > Thank you,
>> >> >
>> >> >
>> >> > On Sat, Nov 12, 2011 at 12:01 PM, Andy Clement
>> >> > <andrew.clement@xxxxxxxxx>
>> >> > wrote:
>> >> >>
>> >> >> Hi,
>> >> >>
>> >> >> Not quite sure what you want to achieve here, maybe share some
>> >> >> pseudocode that shows your intention?
>> >> >>
>> >> >> Once you have the joinpoint object it isn't used for matching a
>> >> >> second
>> >> >> time.  If you want to advise advice, you use a pointcut that matches
>> >> >> it, like adviceexecution().
>> >> >>
>> >> >> If you want to 'call' some advice in a more direct way rather than
>> >> >> rely on implicit invocation, perhaps you could use annotation style
>> >> >> aspects and then call the advice directly passing everything it
>> >> >> needs.
>> >> >>  (since the advice methods are not 'anonymous' like they are in code
>> >> >> style aspects).
>> >> >>
>> >> >> Andy
>> >> >>
>> >> >> On 11 November 2011 07:42, Andres Barrera <andres397@xxxxxxxxx>
>> >> >> wrote:
>> >> >> > Hello, I got a question, I have a JoinPoint instance (for example,
>> >> >> > the
>> >> >> > one
>> >> >> > that you get when you use thisJoinPoint keyword), I´m receiving it
>> >> >> > from
>> >> >> > another aspect, and I need to match it in the receiving aspect, so
>> >> >> > an
>> >> >> > advice
>> >> >> > can intercept it. How can I do that?
>> >> >> > Thank you,
>> >> >> >
>> >> >> > --
>> >> >> > Andrés Barrera
>> >> >> >
>> >> >> > _______________________________________________
>> >> >> > 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
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > Andrés Barrera
>> >> >
>> >> > _______________________________________________
>> >> > 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
>> >
>> >
>> >
>> > --
>> > Andrés Barrera
>> >
>> > _______________________________________________
>> > 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
>
>
>
> --
> Andrés Barrera
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


Back to the top