6 Replies Latest reply on Apr 1, 2004 1:12 PM by rkadayam

    Loading interceptor classes at run-time DR3

    rkadayam Newbie

      1) I'm using jboss-aop with some other application servers such as weblogic and websphere. Would this usage construe as a jboss license violation?? The basic stuff works with weblogic 8.1

      2) I'd like to jar load the interceptor classes at run-time and dynamically attach and detach interceptors to advice bindings.

      I noticed that the AdviceBinding.addInterceptor(Class) takes only a "class argument". How can I ask the aspect manager to use a particular class-loader to resolve that class?

      I tried the following from a session bean.

      addNewInterceptor(classname) -> jar loads the class file using some jar-directory conventions and is able to render the interceptor class

      attachInterceptor(pointcut,interceptor) -> does the following

      AdviceBinding binding = new AdviceBinding(pointcut,null);
      binding.addInterceptor(jarLoader.loadClass(interceptor));
      aspectManager.addBinding(binding);

      At the point of adding the binding I get the ClassNotFoundException initiated at the GenericInterceptorFactory. Oh! So do I provide a custom "JarLoadingInterceptorFactory" then? I'm going to try that out.

      any comments/suggestions would be greatly appreciated

      thanks
      rajiv

        • 1. Re: Loading interceptor classes at run-time DR3
          Bill Burke Master

           

          "rkadayam" wrote:
          1) I'm using jboss-aop with some other application servers such as weblogic and websphere. Would this usage construe as a jboss license violation?? The basic stuff works with weblogic 8.1


          Absolutely not as JBoss-AOP is distributed under LGPL. You can embed it anywhere. LGPL is only triggered when you modify JBoss-AOP code.

          "rkadayam" wrote:

          2) I'd like to jar load the interceptor classes at run-time and dynamically attach and detach interceptors to advice bindings.

          I noticed that the AdviceBinding.addInterceptor(Class) takes only a "class argument". How can I ask the aspect manager to use a particular class-loader to resolve that class?

          I tried the following from a session bean.

          addNewInterceptor(classname) -> jar loads the class file using some jar-directory conventions and is able to render the interceptor class

          attachInterceptor(pointcut,interceptor) -> does the following

          AdviceBinding binding = new AdviceBinding(pointcut,null);
          binding.addInterceptor(jarLoader.loadClass(interceptor));
          aspectManager.addBinding(binding);

          At the point of adding the binding I get the ClassNotFoundException initiated at the GenericInterceptorFactory. Oh! So do I provide a custom "JarLoadingInterceptorFactory" then? I'm going to try that out.

          any comments/suggestions would be greatly appreciated

          thanks
          rajiv


          Ok, I've changed the code in CVS head to not create a GenericInterceptorFactory using the classname, but rather it can accept the java.lang.Class itself so this should solve the problem if you get from head.

          You can get latest from CVS and build, or, in the meantime, the problem is that the GenericInterceptorFactory doesn't try and resolve the class until advice bind time. What you may be able to do is the following

          Class interceptorClass = ....;
          Thread.currentThread().setContextClassLoader(interceptorClass.getClassLoader);
          AdviceBinding.addInterceptor(interceptorClass);
          aspectManager.addBinding(binding);
          


          Let me know if this helps.

          Bill

          • 2. Re: Loading interceptor classes at run-time DR3
            rkadayam Newbie

            Thanks I'll give that a shot.

            I have some related questions

            0. Can I reference interceptors, pointcuts just by name instead of their expressions and class-name? I guess I'm just looking for the DTD :-)

            1. Can I add interceptors by name to the Aspect system without binding to a pointcut? I saw a previous version of the XML that could do this.

            2. Similarly I'd like to add a pointcut to the Aspect system without any bindings. I guess AspectManager.addPointcut() should do that trick. ok

            3. And then I'll probably try to create an AdviceBinding(name,pointcut,null,null,null).addInterceptor(<interceptor-name>) and then add this to AspectManager.

            4. If I want to add more at a later time, I'm not sure how I can get access to that old AdviceBinding? AspectManager.getBindings() returned a bunch of strings, are they some sort of references?

            4. Now, how do I remove a single interceptor from the binding? I could do AspectManager.removeBinding(name) but what is that name?

            5. Are there possibilities to run into some name conflicts? Or do you generate some unique keys for the interceptor, aspect and pointcut elements?

            Thanks a bunch !!
            rajiv

            PS: I'm building some tools using the interceptor concept of AOP for some monitoring type tasks. This is cool stuff !!

            • 3. Re: Loading interceptor classes at run-time DR3
              Bill Burke Master

               

              "rkadayam" wrote:
              Thanks I'll give that a shot.

              I have some related questions

              0. Can I reference interceptors, pointcuts just by name instead of their expressions and class-name? I guess I'm just looking for the DTD :-)


              Yes. Look in the tutorial in the WIKI for info on named pointcuts. Everything definable in XML can take a name attribute. Sorry, but I've never written a DTD yet. Something more I have to do before final release.


              "rkadayam" wrote:

              1. Can I add interceptors by name to the Aspect system without binding to a pointcut? I saw a previous version of the XML that could do this.


              Same XML works.

              <interceptor name="BillsIntercetor" class="org.jboss.BillsInterceptor"/>
              <bind ....>
               <interceptor-ref name="BillsInterceptor"/>
              </bind>
              



              "rkadayam" wrote:

              2. Similarly I'd like to add a pointcut to the Aspect system without any bindings. I guess AspectManager.addPointcut() should do that trick. ok


              Yes see tutorial for how to name pointcuts and have them separate from bindings.


              "rkadayam" wrote:

              3. And then I'll probably try to create an AdviceBinding(name,pointcut,null,null,null).addInterceptor(<interceptor-name>) and then add this to AspectManager.

              4. If I want to add more at a later time, I'm not sure how I can get access to that old AdviceBinding? AspectManager.getBindings() returned a bunch of strings, are they some sort of references?

              4. Now, how do I remove a single interceptor from the binding? I could do AspectManager.removeBinding(name) but what is that name?


              You cannot remove an advice or interceptor from a binding. You have to redeploy the whole binding.

              JBoss AOP automatically generates names for interceptors and bindings based on the XML file name and a random number. Take a look at org.jboss.aop.AspectXmlLoader to see how XML is parsed and how it populates.

              If you have suggestions for expanding the API, feel free to play with the code and then submit it. Or post your API change suggestions on a different topic. You probably want an addInterceptor method on AspectManager. There is an addInterceptorFactory.


              "rkadayam" wrote:

              5. Are there possibilities to run into some name conflicts? Or do you generate some unique keys for the interceptor, aspect and pointcut elements?

              Thanks a bunch !!
              rajiv

              PS: I'm building some tools using the interceptor concept of AOP for some monitoring type tasks. This is cool stuff !!


              There is the possibility of running into name conflicts if you name the pointcuts, interceptors, aspect, or bindings yourself.

              Bill

              • 4. Re: Loading interceptor classes at run-time DR3
                rkadayam Newbie

                 

                "Bill Burke" wrote:


                You cannot remove an advice or interceptor from a binding. You have to redeploy the whole binding.

                If you have suggestions for expanding the API, feel free to play with the code and then submit it. Or post your API change suggestions on a different topic. You probably want an addInterceptor method on AspectManager. There is an addInterceptorFactory.


                I can understand the simplification in AdviceBinding to not maintain interceptor references explicitly but just array of interceptor factories to benefit performance. But even if I have to re-deploy the advice binding, I'd like to somehow pick out that one interceptor I want to remove. I noticed GenericInterceptorFactory has a "getClassName". Would it then make sense to add this method to InterfaceFactory? So that I could maybe parse the list of interceptor factories find the one that returns my interceptor class, remove it and recreate the AdviceBinding and add it to the AspectManager.

                For now I could just cast the IFs to GenericInterceptorFactory.

                I'm not too thrilled with the above approach but do you have any other suggestions without compromising performance?

                Also would it make sense to allow an InterceptorFactory to be passed in AdviceBinding.addInterceptor() so that we can over-ride Generic if required? In fact over here I would much rather call it "attach" instead of "add". Or the alternative would be to have something like AspectManager.createInterceptor(name,class,deployment-model, interceptor factory)

                AspectWerkz had a very similar method call like above except they did not have the concept of interceptor factory but allowed the "ClassLoader" itself to be passed as argument so you could practically load it from anywhere.

                I envision interceptors to be attached and detached on regular basis. Consider someone trying to monitor some custom events using interceptors and they would be required to be easily swappable.

                Thanks for all your help
                rajiv

                • 5. Re: Loading interceptor classes at run-time DR3
                  Bill Burke Master

                  How about we take this approach. You change what you want in source code to get your stuff to work. Send code changes to me. If they are good, I'll give you CVS access and you can commit yourself, or you can just have me do it. Deal?? This way, you can get the features you want without having to wait on me. I will review all commits of course :)

                  Deal?

                  Bill

                  • 6. Re: Loading interceptor classes at run-time DR3
                    rkadayam Newbie

                    All right, I'll give it a try.

                    -thanks
                    -rajiv