1 / 19

Comparison of Different AOP Approaches

Comparison of Different AOP Approaches. Presented by: Xiaojing Wang. Outline. Problem Related work Comparison criteria AOP Approaches for comparison Results Conclusion. Problem. Not fully matured Evaluation is important. Related Work. Mik Kersten

ivy
Download Presentation

Comparison of Different AOP Approaches

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Comparison of Different AOP Approaches Presented by: Xiaojing Wang

  2. Outline • Problem • Related work • Comparison criteria • AOP Approaches for comparison • Results • Conclusion

  3. Problem • Not fully matured • Evaluation is important

  4. Related Work • Mik Kersten • AspectJ, AspectWerkz, JBossAOP, SpringAOP • how to handle AOP language mechanisms • how to integrate with existing development tools, environments, and libraries • Konstantin Ignatyev • CGLIB, Nanning, AspectWerkz,JBossAOP, and HiveMind • use advice to count the number of invocations of a TestInterface method • Alexandre Vasseur • AspectJ, AspectWerkz, JBossAOP, SpringAOP, CGLIB, and dynAOP • use AWbench to measure the relative performance of AOP/Interceptor frameworks

  5. Comparison Criteria • Pointcut • Advice • Aspect declaration

  6. Terms – 1 • Join point: well-defined points in execution of program • Pointcut: refers to collections of joint points and certain values at those join points • Advice: method-like constructs used to define additional behavior at joint points • Aspect: units of modular crosscutting implementation composed of pointcuts, advice, and ordinary Java member declarations.

  7. Terms – 2 • Inter-type declaration (also called introduction): additional fields, methods, constructors for classes • Weave: the process of inserting aspect code into other code, can be done at build time, load time, and run time. • Interceptor: an Aspect with only one advice named "invoke". • Mixin: a kind of generic type, can improve the flexibility of Java class hierarchies, thereby improving the ability to modularize code and compose features

  8. AOP Approaches for Comparison • AspectJ • JBossAOP • Nanning

  9. AspectJ • Extension to Java • Define its own keyword to implement Aspect • Pointcuts: 8 types • Invocation, initialization, access, Exception handling, control flow, containment, conditional, and context • Pointcut operator: &&, || and ! • 3 types advice: before, after, and around

  10. JBossAOP • plain Java class • Pointcuts • Pointcut operator: &&, || and ! • Advice • Using interceptor • Using XML or annotation • Only support around advice

  11. Nanning • Consist of a set of mixins • Interface, target-object, interceptors • Pointcuts • Helper class P • Pointcut pointcut = P.methodName("set.*"); • Advice • Using interceptor • Using dynamic proxy

  12. Pointcut – 1

  13. Pointcut – 2

  14. Advice

  15. Aspect Declaration – AspectJ • Using Java-like code public class HelloWorld { public void say ( String msg ) { System.out.println ( msg ); } public static void main ( String[ ] args ) { new HelloWorld ( ).say ( "Hello, world! " ); } } public aspect HelloWorldAspect { pointcut sayPoint ( ): execution (void HelloWorld.say ( String )); after( ): sayPoint( ) { System.out.println( "Over!" ); } }

  16. Aspect Declaration – JBossAOP // HelloWorldInterceptor.java import org.jboss.aop.advice.Interceptor; import org.jboss.aop.joinpoint.Invocation; public class HelloWorldInterceptor implements Interceptor { public String getName(){ return "HelloWorldInterceptor"; } public Object invoke (Invocation invocation) throws Throwable { System.out.print ("Hello, "); // invokes next interceptor or actual method return invocation.invokeNext(); } } // jboss-aop.xml <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <aop> <bind pointcut="execution(public void HelloWorld-&gt;say(java.lang.String))"> <interceptor class="HelloWorldInterceptor"/> </bind> </aop>

  17. Aspect Declaration – Nanning AspectInstance instance = new AspectInstance(); Mixin mixin = new Mixin(Interface.class, new Target( )); Method method = Interface.class.getMethod("call", null); mixin.addInterceptor(method, new MethodInterceptor( ) { public Object invoke(Invocation invocation) { System.out.println("Hello World! " + invocation.getMethod() + " was called!"); return invocation.invokeNext( ); } }); instance.addMixin(mixin); Interface proxy = (Interface) instance.getProxy( ); proxy.call();

  18. Conclusion • AspectJ provides most complet pointcut and advice • JBossAOP ignores some uncommonly used pointcut and only uses around advice • Nanning is not a mature tool, which uses dynamic proxy to express aspect instead of join points, pointcut, and advice. But it is simple to learn and use. • Recommend to use: AspectJ

  19. Questions?

More Related