4 Replies Latest reply on Nov 9, 2005 8:34 AM by Guadalupe Ortiz

    Doubts about dynamic AOP

    Guadalupe Ortiz Newbie

      I have got various doubts about dynamic AOP:
      * First of all, I tried tle example dynamic-aop in the tutorial and it worked perfectly, but all files are mixed altoguether so I wanted to see in different steps. So first of all I compile the POJO class and the jboss-aop.xml in order to prepare all the classes. Then I compile Driver class and SimpleInterceptor, should I include again the jboss-aop.xml with the prepare target?

      * Secondly I tried to the dynamic aop with the example "package". So to compile and 'jar' The POJO class with the interceptors provided in that example and adding the prepare all in the aop.xml. Then in a diferent jar I compile the Driver and a new Interceptor. Something gets wrong there because it does not include the Driver in the jar. My first questions about this example are, is it allowed to add some interceptor at compile time and at the same time prepare all the methods for dynamic interceptors? What should I include in the aop.xml in the dynamic jar?

      * Finally, if I have any jar prepared for dynamic interceptors. How can I just add a new interceptor which should be included in any invocation to that jar from any other class?

      Thank-you very much in advance, Any help/information in any of the topics is welcome!!


        • 1. Re: Doubts about dynamic AOP
          Kabir Khan Master

          In JBoss AOP there is a 2 phase process.

          1) Weaving
          This stage can take place either at compile time or loadtime. In this phase it will add in the hooks needed for AOP. It will add the same hooks for joinpoints matching a pointcut expression from a bind or prepare element in your -aop.xml file. This stage will also perform interface introductions, and add any necessary mixins.

          2) Binding
          When you first create an instance of a class it will check your -aop.xml file to see what advices should be added to the hooks added in stage 1). JBoss AOP internally uses the dynamic api at this stage to add these (take a look at org.jboss.aop.AspectXMLLoader.java http://anoncvs.forge.jboss.com:8080/viewrep/~raw,r=1.74/JBoss/jboss-aop/src/main/org/jboss/aop/AspectXmlLoader.java) . It finds what advices to add from what is listed in the bind elements in the xml. If your xml only contains prepare elements an aop.xml should not be necessary at this stage.

          You can use the dynamic API to add any advices you like to any joinpoint that was prepared in stage 1), but obviously these aspects will need to be made available on your classpath somehow. If you already know which aspects you will be using, it makes sense to declare them in an -aop file and make this file accessible in stage 2)

          • 2. Re: Doubts about dynamic AOP
            Guadalupe Ortiz Newbie

            Thnaks a lot for the answer! I still have some additional doubts. First let me check if I understood correctly.
            * The "POJO class" has its own aop.xml with, for instance, the prepare statement.
            * The invoker class (i.e. Driver), includes a reference to the POJO aop.xml in order to add the dynamic aspects
            I think that is ok, then I still have some doubts (they are not related altogether):
            1. If I want to add an aspect dynamically and I want this aspect to be applied whenever I invoke the POJO class from any other class, how can I do it? (I mean not necessarily to add the dynamic aspect from the Driver that is the one that is going to do the invocation)

            2. What if I have the POJO class wit whichever aspects and I do the invocation from the Driver, and I want the invoker (Driver) also to have aspects itself. I tried it and I could not make it work. It did not provide problems at compilation but the aspect was not executed at runtime.

            3. An step further: I have got the POJO with the prepare statement I want to add aspects dynamically from the invoker (Driver), but Driver will also have aspects itself; how can I specify that the dynamic bindings are related to the POJO aop.xml and not to the Driver one?

            Thanks a lot for your help!!

            • 3. Re: Doubts about dynamic AOP
              Kabir Khan Master

              1) and 3)

              If I have understood you correctly, you specify this with the pointcut you use when dynamically adding the binding. This narrows down where the joinpoint is applied to.

              2) Do yoiu mean caller pointcuts here? It should be possible to prepare these and add aspects dynamically here too.

              • 4. Re: Doubts about dynamic AOP
                Guadalupe Ortiz Newbie

                I better explain myself with examples:
                * We have POJO class and its aop.xml with the prepare all statement
                * We have got Driver1.java which adds and interceptor SimpleInterceptor.class:
                AdviceBinding binding = new AdviceBinding("execution(POJO->new(..))", null);
                * We have Driver2.java. I want that SimpleInterceptor remains from when Driver1 added it, not only for its invocation. But it is not applied when I execute Driver 2

                2) and 3)
                * We have POJO class and its aop.xml with the prepare all statement
                * I manage to add dynamic execution aspect to pojo and call aspect to Driver, but only dynamically:
                AdviceBinding binding2 = new AdviceBinding("all(Driver)", null);
                but it does not work if I neter in the Driver aop.xml file:

                I think that it is because it automatically select the Pojo aop.xml file, cannot the POjo and the Driver have different xml file? HOw can I mange to make both "work"?

                Thanks a lot!!!