13 Replies Latest reply on Nov 12, 2008 9:28 AM by emmartins

    Classloading docs?

    emmartins

      Is there a doc regarding MC class loaders, similar to this one -> http://www.jboss.org/community/docs/DOC-10290 ?

      We need to create class loaders for javassist generated classes, for jboss AS 4.x it was like this:

      UnifiedClassLoader ucl = (UnifiedClassLoader) Thread
      .currentThread().getContextClassLoader();
      UnifiedLoaderRepository3 lr = (UnifiedLoaderRepository3) ucl
      .getLoaderRepository();
      RepositoryClassLoader cl = lr.newClassLoader(
      getTempClassDeploymentDir().toURL(), new File(
      getUnitJarFile().getName()).toURL(), true);

      Now the context class loader is a BaseClassLoader and looking at that object through debug I don't find something similar as the "old" repository :-)

      Thanks in advance,
      Eduardo
      Mobicents team

        • 1. Re: Classloading docs?
          alesj

           

          "emmartins" wrote:

          UnifiedClassLoader ucl = (UnifiedClassLoader) Thread
          .currentThread().getContextClassLoader();
          UnifiedLoaderRepository3 lr = (UnifiedLoaderRepository3) ucl
          .getLoaderRepository();
          RepositoryClassLoader cl = lr.newClassLoader(
          getTempClassDeploymentDir().toURL(), new File(
          getUnitJarFile().getName()).toURL(), true);

          Due to such hacks, we made new CL more bullet proof. ;-)

          "emmartins" wrote:

          Now the context class loader is a BaseClassLoader and looking at that object through debug I don't find something similar as the "old" repository :-)

          Repository == Domain.

          ClassLoaderSystem --> ClassLoaderDomain --> ClassLoader
          Check AbstractLevelClassLoaderSystemDeployer on how this all fits together.



          • 2. Re: Classloading docs?
            emmartins

            Ok, so I understand the ClassLoaderSystem, which I can simply get using .getInstance(), then I can use .registerClassLoaderPolicy(String domainName, ClassLoaderPolicy policy) to get a new domain and related class loader, my question now is how do I create the policy that "adds" to the classpath the directory where we generated classes. Any hint? :-)

            • 3. Re: Classloading docs?
              alesj
              • 4. Re: Classloading docs?
                slaboure

                guys, don't we have better doc for people wanting to try something like this?

                • 5. Re: Classloading docs?
                  alesj

                   

                  "sacha.labourey@jboss.com" wrote:
                  guys, don't we have better doc for people wanting to try something like this?

                  You do. It's probably sitting 10m away from you. ;-)

                  Poke him about this
                  - https://jira.jboss.org/jira/browse/JBCL-10
                  many people have tried, none have succeedded. ;-)
                  And we're still looking for a couple of them who dared to ask ... :-)


                  • 6. Re: Classloading docs?
                    emmartins

                     

                    "alesj" wrote:
                    What exactly are you trying to do/hack? :-)


                    Putting the whole process in a simple manner, we monitor deployment of specific jars (JAIN SLEE deployable units), extract it to a directory in the server's temp one, and load its content (some is abstract so we need to do concrete implementations with javassist) to a specific class loader. This class loader now (Mobicents JAIN SLEE 1.2.x and JBoss AS4) is connected to the shared repository (the code to create it is in the first post) but in next version, compliant with JAIN SLEE 1.1 specs, we will need to support some kind of class loader composition among deployable units.

                    So... right now what we are exactly needing with this stuff is to create a class loader pointing to the URL where the deployable unit content was unpackaged and another class loader pointing to the URL where the concrete impl of abstract JAIN SLEE components was generated.

                    I will look at this links you shared, thanks :-)

                    • 7. Re: Classloading docs?
                      emmartins

                      Found this class VFSClassLoaderPolicy, looking at code it seems that if used in ClassLoadersystem it will create the class loader pointing to the VFS roots defined, what we need now, did I miss something?

                      • 8. Re: Classloading docs?
                        emmartins

                        almost there:

                        VirtualFile tempClassDeploymentDirVF = VFS.getRoot(getTempClassDeploymentDir().toURL());
                        VFSClassLoaderPolicy classLoaderPolicy = VFSClassLoaderPolicy.createVFSClassLoaderPolicy(tempClassDeploymentDirVF);
                        ClassLoader classLoader = classLoaderSystem.registerClassLoaderPolicy(classLoaderPolicy);
                        


                        This registers the policy pointing to the URL in the default domain, that's fine, the issue now is that once I change to this class loader it doesn't see other classes in the class loader domain. Perhaps any config detail of the policy is missing?

                        • 9. Re: Classloading docs?
                          alesj

                          Perhaps setting parent domain while registering it into system would help?

                          • 10. Re: Classloading docs?

                             

                            "emmartins" wrote:
                            almost there:

                            VirtualFile tempClassDeploymentDirVF = VFS.getRoot(getTempClassDeploymentDir().toURL());
                            VFSClassLoaderPolicy classLoaderPolicy = VFSClassLoaderPolicy.createVFSClassLoaderPolicy(tempClassDeploymentDirVF);
                            ClassLoader classLoader = classLoaderSystem.registerClassLoaderPolicy(classLoaderPolicy);
                            


                            This registers the policy pointing to the URL in the default domain, that's fine, the issue now is that once I change to this class loader it doesn't see other classes in the class loader domain. Perhaps any config detail of the policy is missing?


                            classLoaderPolicy.setImportAll(true); // if you want to see other classes in the domain
                            classLoaderPolicy.setExportAll(ExportAll.NON_EMPTY)); // if you want others to see your classes

                            • 11. Re: Classloading docs?

                               

                              "sacha.labourey@jboss.com" wrote:
                              guys, don't we have better doc for people wanting to try something like this?


                              What makes you think I would document people creating their own classloaders?
                              (I will but this stuff will be in the reference guide rather than the user guide).
                              JavaEE says its illegal for an application to create a classloader.

                              The approach described won't even work with OSGi style classloading.
                              The method works because currently things are using the "big ball of mud"
                              classloading policies.

                              The correct way is to modify the classpath of a deployment using
                              one of the methods Ales showed.
                              Which is actually deployer docs rather than classloader docs. ;-)

                              • 12. Re: Classloading docs?
                                emmartins

                                 

                                "adrian@jboss.org" wrote:
                                "sacha.labourey@jboss.com" wrote:
                                guys, don't we have better doc for people wanting to try something like this?


                                What makes you think I would document people creating their own classloaders?
                                (I will but this stuff will be in the reference guide rather than the user guide).
                                JavaEE says its illegal for an application to create a classloader.

                                The approach described won't even work with OSGi style classloading.
                                The method works because currently things are using the "big ball of mud"
                                classloading policies.

                                The correct way is to modify the classpath of a deployment using
                                one of the methods Ales showed.
                                Which is actually deployer docs rather than classloader docs. ;-)


                                Thanks for you help Adrian. Regarding the "correct way", we receive the deployable unit jars via JMX, then unpack and process it, do you mean we should go for a MC deployer for it, and also for classes generated?

                                • 13. Re: Classloading docs?
                                  emmartins

                                   

                                  "adrian@jboss.org" wrote:

                                  classLoaderPolicy.setImportAll(true); // if you want to see other classes in the domain
                                  classLoaderPolicy.setExportAll(ExportAll.NON_EMPTY)); // if you want others to see your classes


                                  It worked, thanks :-)