Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > AspectJ: how i get to know, who executed 'thisJoinPoint'?

Reply
Thread Tools

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

 
 
linuxadmin@yandex.ru
Guest
Posts: n/a
 
      01-09-2007
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!

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      01-10-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) 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().toStrin g());
}
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[])";
}
}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Get file path of script being executed Ubaldo Villaseca Ruby 3 11-14-2007 06:32 PM
Does this finally get executed ? GIMME Java 14 10-30-2004 09:10 AM
aspnet_wp won't get executed Jaehong ASP .Net Security 1 07-17-2003 06:21 PM



Advertisments