[jboss-user] [JBoss AOP] - Re: howto hotswap ?

flaviarnn do-not-reply at jboss.com
Mon Sep 25 15:53:04 EDT 2006


Hi, Birgen!

To enable the hotswap feature, you need to execute you system with the java 5 agent enabled, and pass the "hotSwap" parameter to this agent, like this:

java your_app your_params -javaagent:jboss-aop-jdk50.jar=-hotSwap 

You can have more instructions on this page:
http://labs.jboss.com/portal/jbossaop/docs/1.5.0.GA/docs/aspect-framework/reference/en/html/running.html#d0e3054

To use the hotswap, all you need to do is invoke the dynamic AOP operations provided by JBoss AOP. Everytime you add or remove an aspect to the system the changes will be performed through hotswap.

To give you an example, suppose you want to add an Interceptor to JBoss AOP. Consider your interceptor is called MyInterceptor. So, you can add both to the system like this:

  | // create a binding, defining a pointcut expression
  | AdviceBinding binding = new AdviceBinding("execution(public * POJO->method())", null);
  | 
  | // this line associates MyInterceptor to your advice binding
  | binding.addInterceptor(MyInterceptor.class);
  | 
  | //finally, add this binding tho the JBoss AOP system
  | AspectManager.addBinding(binding);
  | 
  | 

The last line deploys the binding, and results in the hotswap of all classes affected by this binding. If you want to specify a cflow constraint, you can pass the cflow expression as the second argument of the AdviceBinding constructor.

Another example adds a binding associated with an advice, instead of an interceptor (suppose your advice method is MyAspect.myAdvice()):


  | // create a binding again, defining a pointcut expression
  | AdviceBinding binding = new AdviceBinding("execution(public * POJO->method())", null);
  | 
  | // these lines deploy your aspect to the system, the parameter is the name of your class; the second parameter should not be used by end users
  | AspectFactory af = new GenericAspectFactory("MyAspect", null);
  | AspectDefinition ad = new AspectDefinition("MyAspect", Scope.PER_VM, af);
  | AspectManager.addAspectDefinition(ad);
  | 
  | // this line adds the advice to this binding
  | binding.addInterceptorFactory(new AdviceFactory(ad, "myAdvice");
  | 
  | //finally, add this binding tho the JBoss AOP system
  | AspectManager.addBinding(binding);
  | 

Notice you can define the Scope as you wish, like Scope.PER_CLASS, Scope.PER_INSTANCE, and others.
Besides, you can play along with these examples, adding interceptors and advices to one single binding.

To remove the binding, invoke the removeBiding method of AspectManager class.


If you have any more questions, or problems to use hotswap, please, ask again.

Regards,
Flavia

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

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



More information about the jboss-user mailing list