AspectJ: how i get to know, who executed 'thisJoinPoint'?

Discussion in 'Java' started by linuxadmin@yandex.ru, Jan 9, 2007.

  1. Guest

    hi!

    i want to write a multi-thread tracing library.
    so it is possible that different methods execute one same method
    as a thread simultaneously. something like:

    methodA-instance1 calls methodB-instance1
    methodA-instance2 calls methodB-instance2 and methodB-instance3

    because of that, i need to know, what joinpoint has
    executed/called 'thisJoinPoint'. note, it's not enough
    for me just to know the method, because, again, there may be
    many simultaneous threads of that calling method.

    i hope, you've got the problem.

    thank you!
    , Jan 9, 2007
    #1
    1. Advertising

  2. wrote:
    > i want to write a multi-thread tracing library.
    > so it is possible that different methods execute one same method
    > as a thread simultaneously. something like:
    >
    > methodA-instance1 calls methodB-instance1
    > methodA-instance2 calls methodB-instance2 and methodB-instance3
    >
    > because of that, i need to know, what joinpoint has
    > executed/called 'thisJoinPoint'. note, it's not enough
    > for me just to know the method, because, again, there may be
    > many simultaneous threads of that calling method.


    For inspiration see code below.

    Arne



    LogLeaveAndEnter.aj
    -------------------

    aspect LogEnterAndLeave {
    pointcut alltrace() : call(* *.*(..)) && !within(LogEnterAndLeave)
    && !within(Locator) && !call(* Locator.*(..));
    before() : alltrace() {
    Locator.enter(thisJoinPoint.getSignature().toString());
    }
    after() : alltrace() {
    Locator.leave();
    }
    }

    Locator.java
    ------------

    import java.util.HashMap;
    import java.util.Stack;

    public class Locator {
    private static HashMap data = new HashMap();
    public static void enter(String name) {
    String id = Thread.currentThread().getName();
    Stack stk = (Stack)data.get(id);
    if(stk == null) {
    stk = new Stack();
    data.put(id, stk);
    }
    stk.push(name);
    }
    public static void leave() {
    String id = Thread.currentThread().getName();
    Stack stk = (Stack)data.get(id);
    stk.pop();
    }
    public static String current() {
    String id = Thread.currentThread().getName();
    Stack stk = (Stack)data.get(id);
    return (String)stk.peek();
    }
    public static String previous() {
    String id = Thread.currentThread().getName();
    Stack stk = (Stack)data.get(id);
    if(stk.size() > 1) {
    return (String)stk.get(stk.size() - 2);
    } else {
    return "void main(String[])";
    }
    }
    }
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Jan 10, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Samy
    Replies:
    0
    Views:
    423
  2. Deepak Nayal

    Is AspectJ the BEST ?

    Deepak Nayal, Nov 25, 2003, in forum: Java
    Replies:
    0
    Views:
    392
    Deepak Nayal
    Nov 25, 2003
  3. Peter Litvak
    Replies:
    0
    Views:
    498
    Peter Litvak
    Jan 15, 2004
  4. Bret

    AspectJ int pointcuts

    Bret, Apr 18, 2004, in forum: Java
    Replies:
    1
    Views:
    367
  5. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    228
    Gregory Toomey
    Apr 23, 2004
Loading...

Share This Page