[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Beginner question: intercepting method within a certain context


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() {
            public void run() {
                // do some stuff...
                do {
                    if (lock.tryLock()) {
                        try {
                        } finally {
               } while (someCondition)

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.
Michael Kober