[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Beginner question: intercepting method within a certain context
|
Hi,
Don't mean to divert the OP but I just tried this using 1.6.9
and I am not using the annotation style and
pointcut p1() : call(* *.invoke(..)) && !within( is(AnonymousType) );
does not match and
pointcut p1() : call(* *.invoke(..)) && within( is(AnonymousType) );
matches.
Looks like 'AnonymousType' is working as intended ?
Thanks,
Mohan
On Mon, May 10, 2010 at 9:50 PM, Andy Clement <andrew.clement@xxxxxxxxx> wrote:
> Hi Michael,
>
> The execution joinpoint is not what you want. execution of
> MessageInvocation.invoke() will be happening 'over there' in the
> MessageInvocation type. You are interested in the join point that
> calls it in the Dispatcher type.
>
> Try:
>
> @After("call(* my.package.MessageInvocation.invoke(..)) &&
> withincode(* Dispatcher.dispatch(..))")
>
> Although without trying it out I can't tell you if the anonymous inner
> class will interfere with things.
>
> Andy
>
> On 10 May 2010 03:09, Michael Kober <michael.kober@xxxxxxxxxx> wrote:
>> Hi,
>>
>> I'm an AspectJ beginner and have the following problem:
>>
>> I want to add an aspect after a method call but only when it is done in a
>> certain context (see following pseudo-code):
>>
>> class Dispatcher:
>>
>> public void dispatch(MessageInvocation invocation) {
>> new Thread(new Runnable() {
>> @Override
>> public void run() {
>> // do some stuff...
>> do {
>> if (lock.tryLock()) {
>> try {
>> messageInvocation.invoke();
>> } finally {
>> lock.unlock()
>> }
>> }
>> } while (someCondition)
>> }
>> }).start();
>>
>> I want to intercept the invoke() method of MethodInvocation, but only when
>> it is called in the context of the dispatch method in class Dispatch. Is
>> this possible? I tried to use within / withincode but without success - but
>> maybe I'm just getting the pointcut definition wrong (I use Annotation
>> style):
>>
>> @After("execution(* my.package.MessageInvocation.
>> invoke(..)) && withincode(* Dispatcher.dispatch(..))")
>>
>> Any help appreciated.
>> Thanks
>> Michael Kober
>> _______________________________________________
>> 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
>