[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: New ClassLoader initial checkin

adrian@jboss.org do-not-reply at jboss.com
Fri Apr 27 06:54:27 EDT 2007


Design.

ClassLoaderPolicy

In the new ClassLoader, you don't really deal with classloaders at all.
You deal with ClassLoaderPolicys.
https://svn.jboss.org/repos/jbossas/projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/ClassLoaderPolicy.java

This includes things like what packages you export, what you import, how to get
resources and other things related to defining classes.

ClassLoaderSystem and Domains

Additionally, the idea of a LoaderRepository is replaced with a ClassLoaderDomain
[url]https://svn.jboss.org/repos/jbossas/projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/ClassLoaderDomain.java[/url'
and a ClassLoaderSystem acting as a factory and a repository of domains.
https://svn.jboss.org/repos/jbossas/projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/ClassLoaderSystem.java
Each ClassLoaderSystem has a "default domain".

Example psuedo code:

  | // NOTE: Singleton using the spi, but implementations can be instantiated
  | // directly to produce multiple classloading systems
  | // (which has proved useful in the tests)
  | 
  | ClassLoaderSystem system = ClassLoaderSystem.getInstance();
  | 
  | // Whatever
  | MyClassLoadPolicy policy = ...
  | 
  | // Register with the default domain, there are other methods to create
  | // and register with different domains
  | ClassLoader cl = system.registerClassLoaderPolicy(policy);
  | 

Uglyness and security

To remove some ugliness from the code, the spi is split into 2 parts.
The main part is what people will use
https://svn.jboss.org/repos/jbossas/projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/
but these extend base implementations
https://svn.jboss.org/repos/jbossas/projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/base/

The idea is that the base implementations use package private methods
to talk to each other about state, registration, etc. and issue well defined "callbacks"
into the main spi. The advantages being:

1) Removal of ugliness - you don't see "nitty gritty" in the main spi

2) Security - you can't break the spi nor can anybody get access to things
they shouldn't. 

For the same reason, I've defined a lot of callbacks methods in the main spi
as protected since they should only be used as callbacks not by any random code.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4041338#4041338

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4041338



More information about the jboss-dev-forums mailing list