10 Replies Latest reply on Feb 11, 2005 5:28 PM by natebowler

    Running precompiled AOP classes on JBoss 4.0.0

    natebowler

      I'm running JBoss 4.0.0 and JBoss AOP 1.0 FINAL. In my application I would like to instrument my classes at compile time using AOPC.

      It seems I have everything working. I've modified my Ant build process and I can see the changes being made to my class files. It appears the correct methods are being captures and the correct class files being modified.

      However, when I deploy and run my application, my Interceptor code is not called.

      Most of the examples I've seen for installing AOP seem to be related to loadtime instrumentation.

      My assumption has been that if I am only interested in precompiled AOP, the only runtime requirement are the JAR files included in the AOP distribution:

      javassist.jar
      trove.jar
      concurrent.jar
      jboss-aop.jar
      (jboss-common.jar is already in JBoss 4.0.0)

      In order to get my simple test to to work, I've tried packaging my Interceptor class in a ".aop" module (META-INF/jboss-aop.xml), and modifying my application.xml file to include this, adding jboss-aop.deployer.

      But nothing I do causes my code to be executed.

      I don't get any errors. If I remove, say javassist.jar, from my deploy I get an error saying the methods that have been instrumented are not found. So, I know AOPC is doing something to my classes.

      Is there something I may be missing?

      My jboss-aop.xml looks like this:
      <?xml version="1.0" encoding="UTF-8"?>







      <interceptor-ref name="optimisticlockretry"/>

        • 1. Re: Running precompiled AOP classes on JBoss 4.0.0
          natebowler

          without the brackets...

          ?xml version="1.0" encoding="UTF-8"?
          aop
          interceptor name="optimisticlockretry" class="biz.OptimisticLockRetryInterceptor"/

          pointcut name="taskMethods" expr="execution(public static * biz.TaskMethods-addTask*(..))"/
          pointcut name="templateTaskMethods" expr="execution(public static * biz.TemplateTaskMethods-addTemplateTask*(..))"/

          bind pointcut="taskMethods OR templateTaskMethods"
          interceptor-ref name="optimisticlockretry"/
          /bind
          /aop

          • 2. Re: Running precompiled AOP classes on JBoss 4.0.0
            bill.burke

            I think you have to deploy your .aop file outside the EAR.

            You're packaging everything in an EAR, correct?

            If still need to package everything, just package everything in a JAR:

            foo.jar/
            stuff.aop
            stuff.ear

            I think that will work. I'm not sure if plain jars can have nested archives though...so...if that doesn't work put everything in a SAR.

            foo.sar/
            stuff.aop
            stuff.ear
            META-INF/jboss-service.xml

            Let me know if that works.

            • 3. Re: Running precompiled AOP classes on JBoss 4.0.0
              natebowler

              I can try this deployment, but I'm not sure what to put in the jboss-service.xml in the top-level SAR file.

              Yes, I have everything in an EAR right now. My install will look like this, assuming I can get a valid jboss-service.xml

              redrock.sar
              -META-INF/jboss-service.xml // This is the one I need help with

              -redrock.aop
              ----META-INF/
              --------jboss-aop.xml
              ----biz/
              --------Interceptor.class


              -redrock.ear
              ----META-INF/
              --------application.xml
              --------jboss-app.xml
              ----redrock-web.war
              ----redrock.sar
              ----redrock-ejb.jar

              • 4. Re: Running precompiled AOP classes on JBoss 4.0.0
                bill.burke

                try the JAR approach first. I think that works.

                • 5. Re: Running precompiled AOP classes on JBoss 4.0.0
                  natebowler

                  Its running with the new packaging, but it's still not running my Interceptor class. When I disassemble my instrumented classes, I don't see any references to my Interceptor class. Should I be able to see reference to the Interceptor in an instrumented class?

                  This is how my app is now packaged

                  redrock.jar
                  -redrock.aop
                  ----META-INF
                  --------jboss-aop.xml
                  ----biz
                  --------OptimisticLockRetryInterceptor.class
                  -redrock.ear
                  ----redrock-ejb.jar
                  --------biz
                  ------------TaskMethods.class
                  ------------TemplateTaskMethods.class
                  -------------TaskMethods_addTask_5880466260420991488_OptimizedMethodInvocation.class (and others, you get the idea)

                  I've also tried putting the biz.OptimisticLockRetryInterceptor.class in the redrock-ejb.jar, but I get the same result.

                  Again, if I don't have the required AOP jars, I can't see TaskMethods.class at all (thats the error I get). And I can see these files changed after running AOPC.

                  I'm missing something. Am I not setting something up right? Or, is AOPC running on my files but not getting the interceptor in there correctly?

                  • 6. Re: Running precompiled AOP classes on JBoss 4.0.0
                    bill.burke

                    go to the web-console. http://localhost:8080/web-console
                    there is an AOP icon in the tree. What are the unbound pointcuts?

                    • 7. Re: Running precompiled AOP classes on JBoss 4.0.0
                      natebowler

                      Going to the web-console I realized I didn't have jboss-aop.deployer in the deploy/ directory anymore.

                      Once I put that in, it worked with the JAR packaging. Without that folder, it doesn't work.

                      Thanks for the help, but now I'm a little confused. My understanding was that using AOPC made this unnecessary (obviously it doesn't).

                      So, suppose I wanted to use JBoss AOP with precompiled classes in, say, Websphere. I'm assuming this would be the same as using JBoss without the jboss-aop.deployer folder. Isn't there a way to make this work? I had gathered that the deployer folder wasn't necessary with precompiled instrumentation.

                      At any rate, it looks like it is working. Our customers are running JBoss without the jboss-aop.deployer folder, and I suppose we could ship it with our app. However, my hope was to make it all encapsulated in our EAR file (or JAR file, as the case may be).

                      • 8. Re: Running precompiled AOP classes on JBoss 4.0.0
                        bill.burke

                        jboss-aop.deployer holds a couple of things:

                        the JBoss AOP runtime:
                        Aspects are bound when classes are LOADED even with precompilation. What AOPC does is to preprocess the bytecode to weave in the hooks. The aspects are not bound until runtime. The is late-binding.

                        Late-binding is important for a lot of reasons. ONe of which being you can configure your aspects and which aspects are bound on a per-deployment basis, but still not get the overhead of load-time transformation.

                        Hope I am making sense.

                        Bill

                        • 9. Re: Running precompiled AOP classes on JBoss 4.0.0
                          bill.burke

                          one other thing. the jboss-aop.deployer also provides a service that recognizes .aop jars and -aop.xml files that are in the deploy directory.

                          • 10. Re: Running precompiled AOP classes on JBoss 4.0.0
                            natebowler

                            Makes perfect sense. I appreciate the help.