-
1. Re: howto hotswap ?
flaviarnn Sep 25, 2006 3:53 PM (in response to waffels)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 -
2. Re: howto hotswap ?
waffels Sep 27, 2006 6:57 AM (in response to waffels)thanks a lot for your reply Flavia,
you've really helped me on my way ! -
3. Re: howto hotswap ?
waffels Sep 27, 2006 7:32 AM (in response to waffels)Hi,
am trying to run a client-server based app with support for hotswapping, running the server is no problem,
but when running the clientside(on the same pc)
i get the following error if i try to run with the
-javaagent:jboss-aop-jdk50.jar=-hotSwap
argument:
java.lang.ExceptionInInitializerError
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
at org.jboss.aop.HotSwapStrategy$JoinpointStatusUpdater.initialInterceptorChains(HotSwapStrategy.java:259)
at org.jboss.aop.ClassAdvisor.setInterceptorChainObserver(ClassAdvisor.java:1681)
at org.jboss.aop.AspectManager.getAdvisor(AspectManager.java:443)
at src.Client.(Client.java)
Exception in thread "main"
"could not find the main class, program will exit"
does anybody have any ideas what this could be ?
Thanks in advance !
Regards,
Birgen -
4. Re: howto hotswap ?
waffels Sep 27, 2006 8:59 AM (in response to waffels)fixed it, had a stupid typo somewhere...
-
5. Re: howto hotswap ?
waffels Sep 27, 2006 10:28 AM (in response to waffels)i want to intercept the execution of the method
private static void startSend(OutputStream os,File file) throws IOException
so i made the following binding:
AdviceBinding binding = new AdviceBinding("execution(private static void src.Client->startSend(java.io.OutputStream, java.io.File))", null);
binding.addInterceptor(ClientSendFileInterceptor.class);
AdviceBinding binding2 = new AdviceBinding("execution(private * src.Client->startSend(java.io.OutputStream, java.io.File))", null);
AspectManager.instance().addBinding(binding);
but it won't work, is it possible that eclipse is corrupting things, i've added the VM arguments, i can't see what i'm doing wrong, the interception just doesn't happen... -
6. Re: howto hotswap ?
waffels Oct 1, 2006 2:53 AM (in response to waffels)i'm still having troubles getting this to work,
if i add the -javaagent:jboss-aop-jdk50.jar=-hotSwap argument,
the program often crashes saying it can't find the main class,
this crashing depends on the things that are contained in the jboss-aop.xml file
i often get this error:
java.lang.ExceptionInInitializerError
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
at org.jboss.aop.HotSwapStrategy$JoinpointStatusUpdater.initialInterceptorChains(HotSwapStrategy.java:259)
at org.jboss.aop.ClassAdvisor.setInterceptorChainObserver(ClassAdvisor.java:1681)
at org.jboss.aop.AspectManager.getAdvisor(AspectManager.java:443)
at src.Server.(Server.java)
could it be possible that hotswapping doesn't work using the eclipse IDE ? -
7. Re: howto hotswap ?
flaviarnn Oct 8, 2006 9:12 PM (in response to waffels)Hi, Birgen!
I'll take a look at the code and see what could be happening with your application...
But I need some information. What is the version of JVM you are using? And what is your OS?
Besides, I need more information on your jboss-aop.xml file. Could you please tell me what are the things that, when added to (or removed from?) your jboss-aop.xml, result in this crash?
Hope I can help you!