Presentation is loading. Please wait.

Presentation is loading. Please wait.

Comparison of Different AOP Approaches Presented by: Xiaojing Wang.

Similar presentations


Presentation on theme: "Comparison of Different AOP Approaches Presented by: Xiaojing Wang."— 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 AOPinvocationinitializationaccess Exception handling AspectJ Method call/execution, Constructor call/execution Static-initialization initialization get set handler JBoss AOP Method call/execution, Constructor call/execution N/A field get set (via advice) NanningHelper class P

13 Pointcut – 2 AOP control flowcontainmentconditionalcontextoperator AspectJ Cflow cflowbelow within withincode if this target args && || ! JBoss AOP (via specified call stack) within Withincode hasfield has all (via dynamic cFlow) N/A && || ! Nanning Helper class P

14 Advice AOPAdvice AspectJ before after around JBoss AOParound Nanningaround

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

17 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(); Aspect Declaration – Nanning

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?


Download ppt "Comparison of Different AOP Approaches Presented by: Xiaojing Wang."

Similar presentations


Ads by Google