3 Replies Latest reply on Feb 10, 2005 3:37 AM by Artavazd Mehrabyan

    AOP hotdeployment question

    Artavazd Mehrabyan Newbie

      I need aspectize some X classes at runtime, without using SystemClassLoader and jboss-aop.xml,

      You couldn?t find such a sample in the examples folder and tried to run one of your examples in that way.


      I have custom URLClassLoader which loaded with classpath of JBossAOP jars and that classes the code I have used

      public static void main(String[] args) {
      
       try {
       AdviceBinding binding = new AdviceBinding(
      
       "call(int java.util.ArrayList->size()) AND withincode(void Driver->caller())", null);
      
      
      
       binding.addInterceptor(CallerInterceptor1.class);
      
      
      
       AspectManager.verbose = true;
      
      
      
       AspectManager am = AspectManager.instance();
      
      
      
       am.addBinding(binding);
      
      
      
       org.jboss.aop.standalone.SystemClassLoader sc = new org.jboss.aop.standalone.SystemClassLoader( createURLClassLoader() );
      
      
      
       am.registerClassLoader(sc);
      
      
      
       byte[] b = am.translate("Driver", sc);
      
      
      
       Class c = sc.defineClassFromBytes("Driver", b, true);
      
       System.out.println("c="+c);
      
       Method m = c.getMethod("main", new Class[] {String[].class});
      
      
      
       m.invoke(null, new Object[] {new String[] {} });
      
      
      
       }
      
       catch (Exception ex) { ex.printStackTrace(); }
      
       }
      
      
      
      
      
      static URLClassLoader2 createURLClassLoader() throws Exception {
      
       URL urls[] = null;
      
      
      
       File f = new File("resources/aop/jars"); //the path where JBossAOP jars and that classes located
      
      
      
       if (f.isDirectory()) {
      
       File ff[] = f.listFiles();
      
       urls = new URL[ff.length];
      
      
      
       for (int i = 0; i < ff.length; i++) {
      
       urls = ff.toURL();
      
       }
      
       }
      
      
      
       return new URLClassLoader2(urls, null);
      
       }



      It fails to transform bytecode and return null,

      Could you help me and send similar working code or indicate where I should look for that.



        • 1. Re: AOP hotdeployment question
          Bill Burke Master

          To use JBoss AOP you need to transform bytecode. THis can be done in a few ways:

          AOPC:

          THis is our post compiler. Read the doco for more information

          LOAD-TIME Transformation:
          To do load-time transformation you need to be able to hook in a transformer into your classloading. JBoss AOP does this in multiple ways. Please read the doco for more information.

          * SystemClassLoader. JBoss AOP provides a SystemClassLoader implementation that adds hooks for transformation. This has been deprecated in JBoss AOP 1.4

          * Massage java.lang.ClassLoader to add hooks. This is available with AOP 1.1. Please download the distro and read the docs.

          * JDK 5.0 provides a standard way of hooking in an instrumentor through the java.lang.instrument package. JBoss AOP has an agent that can do this. Please read the doco.

          Bill

          • 2. Re: AOP hotdeployment question
            Artavazd Mehrabyan Newbie

            Let me define my problem


            Task:
            I neet to aspectize classes at runtime. No knowledge of what to be done

            Problem:
            Need to run at any complex Java environment, which has it own ClassLoading system and even already overwrites BootStrap & SystemClassLoaders, as a third party code which also loaded dynamicaly

            And I have AOP 1.1 and it says replase SystemClassLoader which I can't, but I can define my one and can load classes only using my custom LocalSubSystemClassLoader, what you would advice to it?

            Thank you

            • 3. Re: AOP hotdeployment question
              Artavazd Mehrabyan Newbie

              Bill, you ask me to look at docs in AOP 1.1
              so in the reference under the 10.2.2.1 bullet with the title 'Loadtime JDK 1.4' written:

              "In order to do loadtime weaving of aspects with JDK 1.4, we had to massage java.lang.ClassLoader."

              thats good for me

              "What you have to do is generate a modification of java.lang.ClassLoader and add this class to the default bootstrap class path (bootclasspath) for your classes to get instrumented at loadtime."


              thats not ok with me

              So the issue is that I can't add this class to the bootstrap class path,
              instead I can try to use this massaged ClassLoader for transforming bytecode locally,
              but problem is that I coldn't manage use AspectXmlLoader for parsing xml correctly,

              and i could not use your org.jboss.aop.standalone.SystemClassLoader without registering it even subclassing of it creates some problems

              So i neet ClassLoader which will work with AspectManager's translate method locally

              AspectManager.instance().translate(String className, ClassLoader loader)


              I need that loader to work without registering or substituting it with any of System, Bootstrap or whatever loaders or other system resources,