1 2 Previous Next 16 Replies Latest reply on Oct 29, 2008 7:14 PM by flavia.rainone

    The use of Hotswapping

    hou84

      Hello,
      My question is: Do the use of the HotSwapping allows the application to take into account changes in the code of the interceptor without having to click once on the "Run" under eclipse.
      For example, If we have this code:

      for(int i=0;i<100000;i++)
      {
       try
       {
       AdviceBinding ab = new AdviceBinding("execution(public * BuyerMAg->imprimer(..))",null);
       ab.addInterceptor(InterceptorInterdImp.class);
       AspectManager.instance().addBinding(ab);
       }catch(Exception e){}
      
      affichage();
      
      }




      And before the end of the loop "for" I change the first interceptor by a new "InterceptorInderImp2". Does the application will be able to take account of the changes at runtime, or I have to "Run" once the application.
      Thank you for the help.

        • 1. Re: The use of Hotswapping
          kabirkhan

          I don't understand the question? The changes will only take effect when the application is running. Try it out

          • 2. Re: The use of Hotswapping
            hou84

            Hello,
            I mean that when the application is running in the "for" loop and before the end of this loop, I change in the code "InterceptorInterdImp" by "InterceptorInterdImp2", the method "affichage" that call "imprimer" will be able or not to run "InterceptorInterdImp2" without to have to re-run the whole application.
            Thank you.

            • 3. Re: The use of Hotswapping
              kabirkhan

              Yes, that's the idea, as long as you have "prepared" BuyerMAg.imprimer(). However, you will end up with 10000 instances of the interceptor at the end of the loop. To see any interceptions you need to call the method as well.

              • 4. Re: The use of Hotswapping
                hou84

                Hello,
                I tried the example below, but the HotSwapping doesn't work, even the example "dynamic aop" where I change it by adding the loop "for" for the first call to "execute", then I changed "SimpleInterceptor" by an other interceptor before the end of the loop "for":

                 public static void main(String[] args) throws Exception
                 {
                 for(int i=0;i<100000;i++)
                 {
                 execute();
                 System.out.println("--------------");
                 }
                 AdviceBinding binding = new AdviceBinding("execution(public * POJO->someMethod(..))", null);
                 binding.addInterceptor(SimpleInterceptor.class);
                 AspectManager.instance().addBinding(binding);
                 execute();
                 }

                But the application doesn't take account of the modification and display the old interceptor "SimpleInterceptor" in the second call to "execute".
                I'm using "jboss-aop_1.5.6.GA" configured under Eclipse 3.1 and I added, to run with hotSwap in "VM arguments"
                -Djboss.aop.path=C:/Driverexemple/DynamicAOP/jboss-aop.xml -javaagent:C:/aop/jboss-aop_1.5.6.GA/lib-50/jboss-aop-jdk50.jar=-hotSwap

                Please tell me what to do.
                Thank you.

                • 5. Re: The use of Hotswapping
                  hou84

                  Hello,
                  I want to add that I have copied "java" files in the "src" folder:
                  - ConstructorInterceptor.java
                  - Driver.java
                  - InstanceInterceptor.java
                  - POJO.java
                  - SimpleInterceptor.java
                  and I added in the classpath the file "jboss-aop.xml".
                  Then I have made the modifications that I have described in the previous message in the "main" method of the class "Driver".
                  I will be very grateful for the help.
                  Thank you.

                  • 6. Re: The use of Hotswapping
                    flavia.rainone

                    Just to confirm that we are on the same page. Have you compiled your java files after editing them? And restarted your application?

                    Notice that there is no such thing as hot deployment on standalone applications. Adding a jboss-aop.xml file at runtime won't take effect.

                    • 7. Re: The use of Hotswapping
                      flavia.rainone

                       

                      Adding a jboss-aop.xml file at runtime won't take effect.

                      I mean that adding a jboss-aop.xml file to classpath at runtime won't take effect.
                      You can, however, load the xml file with org.jboss.aop.AspectXMLLoader.deployXML(URL).

                      • 8. Re: The use of Hotswapping
                        hou84

                        Hello,
                        I have added all the files of the classes and the file "jboss-aop.xml" before starting the application (they are compiled).

                        • 9. Re: The use of Hotswapping
                          flavia.rainone

                          Hi!

                          Now something else occurred to me. Have you added the jboss-aop.xml file at the classpath? If it did, this is the problem.

                          Instead, you must configure the property jboss.aop.path, pointing it to the location of the jboss-aop.xml file in your system.
                          Or, you can add to your classpath a directory called META-INF containing the jboss-aop.xml file.

                          In case I'm wrong, or none of the above works, try running it under verbose mode (-Djboss.aop.verbose=true) and let us know whether JBoss AOP is loading your .xml file or not. Also, make sure that you have prepared POJO->someMethod.

                          • 10. Re: The use of Hotswapping
                            hou84

                            Here is the content of the "jboss-aop.xml" file:

                            <?xml version="1.0" encoding="UTF-8"?>
                            <aop>
                             <prepare expr="execution(public * POJO->someMethod(..))"/>
                            </aop>


                            In "execute" method I have deleted Per instance interception
                             Advised advised = (Advised)pojo;
                             advised._getInstanceAdvisor().insertInterceptor(new InstanceInterceptor());
                             System.out.println("--- pojo.counter++; ---");
                             pojo.counter++;
                            


                            I created META-INF directory and moved "jboss-aop.xml" in it. I also modified the "-Djboss.aop.path" to point to the new location of "jboss-aop.xml". But it doesn't work.

                            So I tried the verbose mode, Here is the new configuration of "VM aguments":
                            -Djboss.aop.verbose=true -Djboss.aop.path=C:/Driverexemple/DynamicAOP/META-INF/jboss-aop.xml -javaagent:C:/aop/jboss-aop_1.5.6.GA/lib-50/jboss-aop-jdk50.jar=-hotSwap


                            I run the application and before the end of the "for" loop I modified "SimpleInterceptor" by "InstanceInterceptor".
                            The verbose mode display after 10000 without interception:
                            --------------
                            --- new POJO(); ---
                            in empty constructor
                            --- adding instance interceptors ---
                            --- pojo.someMethod(); ---
                            in someMethod
                            --------------
                            [trying to transform] SimpleInterceptor
                            [debug] There are no caller pointcuts!
                            [debug] was SimpleInterceptor converted: false
                            [trying to transform] SimpleInterceptor
                            [debug] There are no caller pointcuts!
                            [debug] was SimpleInterceptor converted: false
                            [debug] softmatch succeeded for : POJO org.jboss.aop.advice.AdviceBinding@4a8436a5 execution(public * POJO->someMethod(..))
                            iterate binding 1225222694453:0
                            [debug] added advisor: POJO from binding: 1225222694453:0
                            method matched binding execution(public * POJO->someMethod(..)) public void POJO.someMethod()
                            --- new POJO(); ---
                            in empty constructor
                            --- adding instance interceptors ---
                            --- pojo.someMethod(); ---
                            <<< Entering Simplenterceptor for: POJO$someMethod_2315001504750198986
                            in someMethod
                            

                            Thank you for the help.

                            • 11. Re: The use of Hotswapping
                              hou84

                              Hi,
                              I want to add that for

                              I run the application and before the end of the "for" loop I modified "SimpleInterceptor" by "InstanceInterceptor".
                              that it still intercepting "SimpleInterceptor" and don't take account of the modification to "InstanceInterceptor".
                              Tanks a lot for the help.

                              • 12. Re: The use of Hotswapping
                                flavia.rainone

                                Well, if POJO is being intercepted by SimpleInterceptor, the jboss-aop.xml file is being loaded.

                                What do you mean with modifying SimpleInterceptor by InstanceInterceptor?

                                You can only modify something through the code, like below:

                                public static void main(String[] args) throws Exception
                                 {
                                 // using SimpleInterceptor
                                 AdviceBinding binding = new AdviceBinding("execution(public * POJO->someMethod(..))", null);
                                 binding.addInterceptor(SimpleInterceptor.class);
                                 AspectManager.instance().addBinding(binding);
                                 // check: SimpleInterceptor is being used
                                 execute();
                                
                                 // modifying binding, now I want to use InstanceInterceptor
                                 AdviceBinding newBinding = new AdviceBinding(binding.getName(), "execution(public * POJO->someMethod(..))", null);
                                 newBinding.addInterceptor(InstanceInterceptor.class);
                                 AspectManager.instance().addBinding(newBinding);
                                 // check: Instanceinterceptor is now being used
                                 execute();
                                
                                 }


                                At the moment that you use the name of the old binding in the new binding (at the line that calls the AdviceBinding constructor passing binding.getName() as parameter), you are replacing binding by newBinding. Consequently, you are replacing SimpleInterceptor by InstanceInterceptor.



                                • 13. Re: The use of Hotswapping
                                  hou84

                                  Hello,
                                  The main idea of my researches that I want to have an application where here security rules are implemented through aspects of JBossAOP, this application must to be always running and I want to be able to "add, change and delete aspects at runtime without having to stop the running and then re-run the application".
                                  Is it possible to do this?
                                  Thank you.

                                  1 2 Previous Next