1 2 Previous Next 17 Replies Latest reply on Jun 29, 2004 4:56 PM by bill.burke

    JBoss AOP vs. AspectJ

    rmcdonough

      I've recently been researching both AspectJ and JBoss AOP. As a JBoss user, I am graviating toward JBoss AOP, but I'd like to know what are the advantages of using JBoss AOP over AspectJ, other than being a JBoss product? One thing that AspectJ has going for it now, in my opinion, is nice support in Eclipse, but the need to recompile all of my classes with the AspectJ compiler is a bit unattractive. And can I use JBoss AOP in the JBoss 3.2 series? I'm more curious than anything at this point and would love to hear anyones thoughts on the issue.

      Thanks,

      Ryan-

        • 1. NPE on redeploy (inside aspect library code)
          bill.burke

          I have a simple webapp that makes use of only the TX Apsect libraries for demarcation.

          I am using both the Annotation compiler and the AOPC compilier, packaging up the results in a WAR, and deploying to a JBoss 4.0 server. I have upgraded to FINAL code.

          My issues is that on startup, or first deployment of my WAR file, my code, and the TX interceptors work great. However, once I redploy my WAR file, I get a NullPointerException in my original method signature (which is now the new interceptor method).

          So, if I have a method called saveOrganization() that has been intercepted, after a redployment, I will get the following stacktrace:

          2:34:39,168 ERROR [org.osn.jext.framework.util.RequestInterceptor:124] java.lang.NullPointerException
           at org.osn.homefront.app.service.HomefrontService.saveOrganization(HomefrontService.java)
           at org.osn.homefront.app.OrgSignUp2.submit(OrgSignUp2.java:559)
           at org.osn.homefront.app.OrgSignUp2.pageMain(OrgSignUp2.java:63)
           at org.osn.jext.framework.JSPPageContent.runPageMain(JSPPageContent.java:45)
          


          As you can see, the line number is missing for where the NPE happens at, since it is the new instumented code.

          For shits & giggles, I decompiled that method and here is the code:

           public void saveOrganization(Organization organization)
           throws PersistenceException, BusinessValidationException
           {
           if(((Advisor) (aop$classAdvisor$aop)).doesHaveAspects || _instanceAdvisor != null && _instanceAdvisor.hasInstanceAspects)
           {
           org.jboss.aop.advice.Interceptor ainterceptor[] = aop$MethodInfo_saveOrganization5875559486684723374.interceptors;
           if(_instanceAdvisor != null)
           ainterceptor = _instanceAdvisor.getInterceptors(aop$MethodInfo_saveOrganization5875559486684723374.interceptors);
           HomefrontService_saveOrganization_5875559486684723374_OptimizedMethodInvocation homefrontservice_saveorganization_5875559486684723374_optimizedmethodinvocation =
          new HomefrontService_saveOrganization_5875559486684723374_OptimizedMethodInvocation(aop$MethodInfo_saveOrganization5875559486684723374, ainterceptor);
           homefrontservice_saveorganization_5875559486684723374_optimizedmethodinvocation.arg0 = organization;
           homefrontservice_saveorganization_5875559486684723374_optimizedmethodinvocation.setTargetObject(this);
           homefrontservice_saveorganization_5875559486684723374_optimizedmethodinvocation.typedTargetObject = this;
           homefrontservice_saveorganization_5875559486684723374_optimizedmethodinvocation.setAdvisor(aop$classAdvisor$aop);
           homefrontservice_saveorganization_5875559486684723374_optimizedmethodinvocation.invokeNext();
           } else
           {
           org$osn$homefront$app$service$HomefrontService$saveOrganization$aop(organization);
           }
           }
          


          Now, looking at that, I am not sure exactly where the NPE would be happening at, but the first suspect to me is the aop$classAdvisor$aop variable, since it is static. I wonder if it is getting blown away on the redploy and not set back up properly, since the static constructor might not get ran again?

          Thoughts?



          • 2. Re: JBoss AOP vs. AspectJ
            kabirkhan

            Bill is at Java One, and should be able to give a proper answer when he is back. In the meantime:

            Two people are working on Eclipse support at present, so expect something in that area soon.

            You can use JBoss AOP with 3.2.4 or higher, docs/misc/running_jboss.html in the distribution shows how.

            JBoss AOP comes with a set of aspects (with a LOT more to follow) where you can leverage JBoss services.

            Cheers,

            Kab

            • 3. Re: JBoss AOP vs. AspectJ
              neilloughran

              I'm also interested in this. What are the major reasons for choosing JBoss AOP over AspectJ or even Aspectwerkz?

              • 4. Re: JBoss AOP vs. AspectJ
                bill.burke

                Why JBoss AOP over AspectJ?
                - 100% pure Java
                - annotation support (JDK 1.5 and 1.4)
                - Metadata and annotation override facility
                - load-time transformations (instead of compile time)
                - hotdeployment of aspects (dynamic AOP)
                - per-instance API (dynamic AOP)
                - dynamic CFLOW
                - pluggable pointcuts
                - extended pointcut expressions (has and hasfield as well as typedefs).

                I haven't looked at AspectWerkz since February, but they had limited support in their pointcut expression language at the time (no around for field interception, no constructor interception, no annotation support). They did have better load-time transformation support, but we will catch up on this soon.

                Bill

                • 5. Re: JBoss AOP vs. AspectJ
                  neilloughran

                  Thanks Bill,

                  What do you mean by dynamic? I know that dynamic means different things in the AOP world.. for instance AspectJ folks might say that their CFLOW is dynamic as it collects information as the program is running yet is still to all intents and purposes a compile time technique.

                  I believe Aspectwerkz allows new code to be plugged and unplugged at run time, hence its dynamicism.

                  So what does dynamic mean for JBoss?

                  Cheers
                  Neil



                  "Bill Burke" wrote:
                  Why JBoss AOP over AspectJ?
                  - 100% pure Java
                  - annotation support (JDK 1.5 and 1.4)
                  - Metadata and annotation override facility
                  - load-time transformations (instead of compile time)
                  - hotdeployment of aspects (dynamic AOP)
                  - per-instance API (dynamic AOP)
                  - dynamic CFLOW
                  - pluggable pointcuts
                  - extended pointcut expressions (has and hasfield as well as typedefs).

                  I haven't looked at AspectWerkz since February, but they had limited support in their pointcut expression language at the time (no around for field interception, no constructor interception, no annotation support). They did have better load-time transformation support, but we will catch up on this soon.

                  Bill



                  • 6. Re: JBoss AOP vs. AspectJ
                    bill.burke

                    Dynamic means:
                    * per-instance API. You can define advices that are applied on a per-instance basis. You can attach arbitrary metadata to an instance
                    * Hotdeployment. You can hotdeploy, undeploy, redploy, advice bindings at runtime

                    I do not have support for Hot Swap yet as JDK 1.4 and 1.5 requires debug mode to enable it. See my blog for more thoughts on this... JBoss microkernel gives support for redeployment of classes so HotSwap isn't so important right now to me.

                    Bill


                    • 7. Re: JBoss AOP vs. AspectJ
                      imsathya

                      Thanks Bill,
                      That was very informative.

                      Another query. AspectJ supports the notion of being able to define as to when you need an advice to be executed - before or after. So far as my understanding goes, JBoss AOP appears to be more interception based which appears to say "..when call X is made, execute AspectX first..".

                      Is there support for the before-after like specification provided by AspectJ ? This is important to us when say we want to capture the time taken to execute method X. Using the before-after specifiers facilitates this greatly.

                      Thanks.

                      • 8. Re: JBoss AOP vs. AspectJ
                        imsathya

                        Sorry for replying to my own post.

                        Just another query. Would the interception for an EJB be different from that of a pure Java class ?

                        Here is a test I tried.

                        - Created an entity bean with method findWithID(int) and deployed it in JBoss 3.2.5 following the instructions specified.
                        - I defined a pointcut to intercept call to this method but I found that the advice was not being executed.

                        Then I defined a Java class with the same findWithID(int) and found the interception happening fine.

                        Any extra settings required on the JBoss server ?

                        Thanks.

                        • 9. Re: JBoss AOP vs. AspectJ
                          kabirkhan

                          Hi,

                          Before-After: There is more about this in another post somewhere in this thread, but basically interception in JBoss AOP is both before and after.

                          Example:

                          public class MyInterceptor implements Interceptor
                          {
                           public String getName() { return "MyInterceptor"; }
                          
                           public Object invoke(Invocation invocation) throws Throwable
                           {
                           Object o = null;
                           //You can do "BEFORE" stuff here, e.g.
                           long start = System.currentTimeMillis();
                          
                           //Invoke next method
                           o = invocation.invokeNext();
                          
                           //You can do "AFTER" stuff here, e.g.
                           long end = System.currentTimeMillis();
                           long timeTaken = end - start;
                          
                           return o;
                           }
                          }
                          


                          EJB: It all depends on the packaging. If you get jboss-head from cvs, it contains a new tutorial showing some options for packaging war and ear applications. Also, http://www.jboss.org/wiki/Wiki.jsp?page=RunningWithJBossApplicationServer contains some information on what you need to do to run with JBoss 3.2.5 if you haven't followed these steps already.

                          Cheers,

                          Kab



                          • 10. Re: JBoss AOP vs. AspectJ
                            imsathya

                            Thanks a lot.

                            After going through the documentation, I revisited my deployment to match what had been speciifed but I still cant get it to work.

                            First, I created a .aop of my intercepter class (which I verified worked in the stand-alone mode) :

                            $ jar -tvf SimpleAOP.aop
                             0 Tue Aug 17 00:35:46 IST 2004 META-INF/
                             70 Tue Aug 17 00:35:46 IST 2004 META-INF/MANIFEST.MF
                             0 Tue Aug 17 00:34:10 IST 2004 classes/
                             0 Tue Aug 17 00:34:10 IST 2004 classes/test/
                             0 Tue Aug 17 00:34:10 IST 2004 classes/test/ejb/
                             1409 Tue Aug 17 00:35:20 IST 2004 classes/test/ejb/SimpleInterceptor.class
                             177 Tue Aug 17 00:35:14 IST 2004 META-INF/jboss-aop.xml
                            


                            I modified the $JBOSS_HOME/server/default/conf/jboss-service.xml file to add in the mbean specified in the link :

                             <classpath codebase="lib" archives="*"/>
                             <mbean code="org.jboss.aop.deployment.AspectManagerService"
                             name="jboss.aop:service=AspectManager">
                             <attribute name="EnableTransformer">false</attribute>
                             <!-- only relevant when EnableTransformer is true -->
                             <attribute name="SuppressTransformationErrors">true</attribute>
                             <!-- only relevant when Enabletransformer is true. Optimization is optional
                             only just in case there is a bug in it -->
                             <attribute name="Optimized">true</attribute>
                             <attribute name="Verbose">false</attribute>
                             </mbean>
                            
                             <mbean code="org.jboss.aop.deployment.AspectDeployer"
                             name="jboss.aop:service=AspectDeployer">
                             </mbean>
                            
                             <mbean code="org.jboss.management.j2ee.LocalJBossServerDomain"
                            ...
                            


                            I added the base-aop.xml file to the same directory.

                            I started up my jboss 3.2.5 server - then added my testEJB.jar file to the deploy directory. The beans were deployed successfully.

                            Next, I added the Simple.aop file. When I added it, I got the below message from the server :

                            Incompletely deployed packages:
                            org.jboss.deployment.DeploymentInfo@3142bdd7 { url=file:/Users/sathya/Servers/jboss-3.2.5/server/default/deploy/SimpleAOP.aop }
                             deployer: null
                             status: null
                             state: INIT_WAITING_DEPLOYER
                             watch: file:/Users/sathya/Servers/jboss-3.2.5/server/default/deploy/SimpleAOP.aop
                             lastDeployed: 1092683344241
                             lastModified: 1092683344000
                             mbeans:
                            


                            and the aspect does not get executed when the beans method is executed.

                            Anything I am missing out ??

                            Thanks
                            Sathya

                            • 11. Re: JBoss AOP vs. AspectJ
                              kabirkhan

                              Sorry I'm not able to look at this in very much detail right now.

                              Also, look at combining the .jar and .aop in an ear as shown in the tutorial. The tutorial is by now means a complete guide to all possible packaging options, just shows a few configurations I got working.

                              I have to admit I have not tried running it with 3.2.x yet, what happens if you try it with 4.0?

                              Also, for the AspectManagerService MBean config, you should set EnableTransformer to true.

                              Cheers,

                              Kab

                              • 12. On emore AJ vs. JBAOP Querstion. Was Re: JBoss AOP vs. Aspec
                                rmcdonough

                                So since I started this thread a few months ago, I thought I'd chime back in. Bill, thanks for your very thorough description, but now I have one more question: I've been doing more reasearch on AOP overall and more research on AspectJ and JBossAOP. Now I'm not sure that I'll be phrasing thsi right, but it seems that AspectJ doesn't allow you to apply advice or introduction on an existing class without explicitly defining defining a join point within an Ascpect. Also, once you make this change, you will also have to recompile all your classes again. From what I gather about JBossAOP, it seems that I can just add an annotion to my class and have my class advised? Or better yet, I can just redeploy an aspect and advise a class that was compiled with javac and has no knowledge of any aspect? Just curious if this is a correct understanding of how JBossAOP works.

                                • 13. Re: JBoss AOP vs. AspectJ
                                  kabirkhan

                                  In JBoss AOP you can attach things dynamically via the AspectManager class. You need to prepare your class first:

                                  http://www.jboss.org/wiki/Wiki.jsp?page=JBossAOP Go to Tutorial/Dynamic AOP

                                  • 14. Re: On emore AJ vs. JBAOP Querstion. Was Re: JBoss AOP vs. A

                                     

                                    "rmcdonough" wrote:
                                    .....I've been doing more reasearch on AOP overall
                                    and more research on AspectJ and JBossAOP. Now I'm not sure that I'll be
                                    phrasing thsi right, but it seems that AspectJ doesn't allow you to apply
                                    advice or introduction on an existing class without explicitly defining defining
                                    a join point within an Ascpect. Also, once you make this change, you will also
                                    have to recompile all your classes again.


                                    Hi.
                                    So, to clear things up...
                                    You may introduce sth in AspectJ's aspect to some class without specifying
                                    pointcut (what for would you specify it?).

                                    With AspectJ; to apply advice you always have to specify some kind of
                                    pointcut/join point. In AspectJ the only possibility to apply some advice is by
                                    defining it on some pointcut (but AspectJ people work on annotations).

                                    About recompiling: of course you have to recompile classes (with )
                                    whenever you change sth in AspectJ. But the same goes for JBossAOP (if you
                                    don't use custom classloader). Even if you add some @metadata to some
                                    method - you still need to recompile the class. But, is there some problem with recompiling?

                                    Sincerely,
                                    Tomasz


                                    1 2 Previous Next