|
[AOP]
Opt-out AOP: good or evil ?
[
avasseur
]
There is an interesting option in AspectJ that is named -Xreweavable.
When turned on using any kind of compilation/weaving mode (compiling with ajc, within Eclipse AJDT, doing bynary weaving, or using loadtime weaving), each weaved class keeps track of
Actually, discussions are taking place if this should be the default. An interesting consequence is that it is fairly easy to implement an opt-out AOP engine that simply restores the state prior to weaving, and thus kicks out all the aspects from the application ! There are of course realistic use-cases for it :
This is actually very easy to do when using f.e. AspectWerkz-core as the backend to hook this one in and have it work as well on Java 1.3, and using ASM for the bytecode details. Here is a sample output (I am using AspectJ loadtime weaving to do the weaving first, but that could be done using post compilation with AJC, or compilation from within Eclispe AJDT etc) // in this sample, start the app with AspectJ loadtime weaving (could have been compiled with ajc instead) // and pipe with the UndoAspectJ opt-out engine using the AspectWerkz core // as a backend #java -javaagent:aspectjweaver.jar -Daj5.def=test/aop.xml -javaagent:aspectwerkz-jdk5-2.0.jar -Daspectwerkz.classloader.preprocessor= org.aspectj.ext.undoaspectj.ClassPreProcessor test.undoaspectj.Sample weaveinfo Type 'test.undoaspectj.Sample' (Sample.java:28) advised by around advice from 'test.undoaspectj.Sample$TestAspect' (Sample.java) // here is the opt-out message UndoAspectJ - test/undoaspectj/Sample was affected by test.undoaspectj.Sample$TestAspect // execution without any aspect takes place: Sample.target // without the opt-out we would see the aspect executing: weaveinfo Type 'test.undoaspectj.Sample' (Sample.java:28) advised by around advice from 'test.undoaspectj.Sample$TestAspect' (Sample.java) // execution with aspect takes place: Sample$TestAspect.around Sample.target Post a comment
|