[jboss-user] [JBoss Microcontainer] - ClassLoading delegation

rafael liu do-not-reply at jboss.com
Mon May 3 09:52:55 EDT 2010


rafael liu [http://community.jboss.org/people/rafaelliu] created the discussion

"ClassLoading delegation"

To view the discussion, visit: http://community.jboss.org/message/540775#540775

--------------------------------------------------------------
It's actually not a MC thing, but it's on MC's expertise...

I'm trying to do a classloader which will chain 2 other classloaders. I need this since I'm making a ContainerApp that will get another web application's context (another WAR), say BookingApp, to dispatch requests.

So whenever ContainerApp has to load classes it will look first at BookingApp, then at ContainerApp classpash itself. My first naive approach was:

public class DelegatorClassLoader extends ClassLoader {
 
        @Override
        public synchronized Class<?> loadClass(String name) throws ClassNotFoundException {
                try { 
                        return bookingClassLoader.loadClass(name);
                } catch (Exception e) {
                        return containerClassLoader.loadClass(name);
                }
        }
 
...
 
}


Which works OK unless classes BookingApp reference ContainerApp, or vice-versa. That is, supposing the WARs had the following classes:

ContainerApp.war:
ContainerOnlyClass

BookingApp .war:
BookingOnlyClass
BookingContainerClass extends  ContainerOnlyClass

The results I get are:

DelegatorClassLoader.loadClass(ContainerOnlyClass) *works*
DelegatorClassLoader.loadClass(BookingOnlyClass) *works*
DelegatorClassLoader.loadClass(BookingContainerClass) *doesn't work*
 

The associated classloader is either ContainerApp or BookingApp, never DelegatorClassLoader. Reading the VM spec it's clear that the reference the class holds in to it's +defining+ classloader, while in my code  DelegatorClassLoader is the +initiator+ classloader.

My question is: doesn't MC VFS has something like this already so I could reuse it? This seems precisely what JBoss does.. Could you point me to some source code?

thanks a lot! cheers

--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/540775#540775]

Start a new discussion in JBoss Microcontainer at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2114]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100503/fbe7326f/attachment.html 


More information about the jboss-user mailing list