[jboss-user] [JBoss AOP] - Re: Dynamic AOP - AspectManager.instance().addBinding() bloc

mane81 do-not-reply at jboss.com
Wed Oct 22 18:10:35 EDT 2008


I tried to reproduce the situation when AspectManager.addBinding(); blocks and I found the same problem:

*** Caller.class ***
import org.jboss.aop.Prepare;

@Prepare("all(this)")
public class Caller {
	private AspectCreator ac;
	
	public Caller() {
		System.out.println("Caller new instance");
		ac = new AspectCreator();
	}
	
	public void method1() {
		System.out.println("Caller.method1()");
	}
	
	public void method2() {
		System.out.println("Caller.method2()");
	}
	
	public void run() {
		while(true) {
			
			method1();
			method2();
			
			try {
				java.util.concurrent.TimeUnit.MILLISECONDS.sleep(4000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			ac.setCond();
			try {
				java.util.concurrent.TimeUnit.MILLISECONDS.sleep(4000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

			method1();
			method2();
		}
	}
	
	public static void main(String[] args) {
		Caller caller = new Caller();
		caller.run();
	}
}
*** Caller.class end ***

*** AspectCreator.class ***
import org.jboss.aop.AspectManager;
import org.jboss.aop.Prepare;
import org.jboss.aop.advice.AdviceBinding;
import org.jboss.aop.pointcut.ast.ParseException;
import aspects.SimpleInterceptor;

@Prepare ("all(this)")
public class AspectCreator {
	private MyThread thread;
	private Boolean cond;
	
	public AspectCreator() {
		cond = false;
		thread = new MyThread();
		thread.start();
	}
	
	public void setCond() {
		synchronized (cond) {
			cond = true;
		}
	}
	
	public boolean getCond() {
		synchronized (cond) {
			return cond;
		}
	}
	
	public void injectAspect() {
		System.out.println("Injecting aspect");
		AdviceBinding binding = null;
		try {
			binding = new AdviceBinding("execution(* Caller->method1(..))", null);
			System.out.println("Binding created");
		} catch (ParseException e) {
			e.printStackTrace();
		}
		binding.addInterceptor(SimpleInterceptor.class);
		System.out.println("Interceptor added");
		AspectManager.instance().addBinding(binding);
		System.out.println("Aspect injected");
	}
	
	private class MyThread extends Thread {
		public void run() {
			while(true) {
				try {
					java.util.concurrent.TimeUnit.MILLISECONDS.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				boolean value = getCond();
				if (value) {
					injectAspect();
				}
				synchronized (cond) {
					cond = false;
				}
			}
		}
	}
}
*** AspectCreator.class end ***


The directories contain the following files:
./DynamicAOP/bin:
Aopper.class
AspectCreator.class
AspectCreator$MyThread.class 
 aspects/
Caller.class

./DynamicAOP/bin/aspects:
SimpleInterceptor.class


I run the example with the following command:
$  ./run-load15.sh DynamicAOP/bin/ -aopclasspath /DynamicAOP/bin/:DynamicAOP/bin/aspects/ Caller

and the output is:
Caller new instance
Caller.method1()
Caller.method2()
Injecting aspect
Binding created
Interceptor added

and then it hangs waiting the return of AspectManager.instance().addBinding(binding);

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4184000#4184000

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4184000



More information about the jboss-user mailing list