[Design the new POJO MicroContainer] - Re: New ClassLoader initial checkin
by adrian@jboss.org
ClassLoaderManager
This is a replacement/port of LoadMgr3.
I originally tried to rewrite this as something intelligble but couldn't get it to work.
So I just copied it and simplified it, e.g. only the Domain deals with the
ClassLoadingTasks now and the ClassLoaderManger doesn't deal with domains
it deals with [Class]Loaders.
After I did this it still didn't work :-)
It was only when I implemented timeouts on the two most important waits
| boolean interrupted = thread.interrupted();
|
| int waits = 0;
|
| try
| {
| while (true)
| {
| try
| {
| if (lock.tryLock(0, TimeUnit.MICROSECONDS) == false)
| {
| // REVIEW: If we've been spinning for more than a minute then there is probably something wrong?
| if (waits++ == 6)
| throw new IllegalStateException("Waiting too long to get the classloader lock: " + this);
| // Wait 10 seconds
| if (trace)
| log.trace(this + " waiting for lock " + thread);
| this.wait(10000);
| }
| else
| {
| if (trace)
| log.trace(this + " aquiredLock " + thread + " holding=" + lock.getHoldCount());
| break;
| }
| }
| catch (InterruptedException ignored)
| {
| }
| }
| }
| finally
| {
| if (interrupted)
| thread.interrupt();
| }
|
that I figured out what was going on.
It started working with the timeouts, but only after a 10 second pause (co-incidence? :-)
A missed notification perhaps?
The answer was there is something subtle in the way the ClassLoaderManager
and the ClassLoader hand off control to each other.
Normally you release locks in the reverse order you aquire them.
Not here. Once I modified the lock release and notifyAll() to match the old
LoadMgr3 code it started working. :-)
Very Voodoo!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4041351#4041351
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4041351
17 years, 8 months
[Design the new POJO MicroContainer] - Re: New ClassLoader initial checkin
by adrian@jboss.org
Back on topic.
So what is missing?
1) Policy
This ClassLoader is very dumb. It relies on you to tell it what the policy is.
The only current implementation of a policy is in the tests
https://svn.jboss.org/repos/jbossas/projects/microcontainer/trunk/classlo...
There are actually two more levels that need to be implemented.
a) VFS layer - write a policy that uses the VFS
b) Dependency and policy construction controller - i.e. from metadata workout
when dependencies are satisifed and create the relevant policies.
This will actually be part of the [Main]Deployer(s) when I plugin the MC to it.
2) Security
The current tests don't run with a security manager enabled, but also I need
to audit the classloader for two things:
a) Where privileged blocks are needed
b) What permissions we need to define, e.g. who can register policies or create domains
3) Caching/BlackListing
There is currenty no caching or black listing (cache misses).
This is going to be a little more complicated to implement since you can't
use a global cache for OSGi. It is no longer the "big ball mud" model.
The type and whether to cache should be part of the Policy.
4) Translater
I added a hook for translating classes, but I'm probably going to remove it
since this is already handled from Java5+ by the agents api in the JDK.
5) TODOs
There are a number of other TODOs and REVIEWs in the code, but these
are fairly minor.
6) Tests
I have some basic tests and I've ported some of the old classloader
tests from the jboss testsuite (where they didn't try to hook into the UCL).
Obviously more are needed. e.g. I have no tests at all for the domain
hierarchy.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4041349#4041349
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4041349
17 years, 8 months