|
MultiClassLoader changes: msg#00016java.enhydra.general
Folks, We have been using enhydra 3.1 for quite sometime now and we have not yet made the transition to 5.1 yet. The multiclass loader that comes with enhydra is ok but seems to be quite old. Moreover we were having troubles trying to share common DODS objects with other servlets and application wars. Hence I have changed the way MultiClassLoader handles parent classloader. I am not quite sure whether these changes are according to your standards or specifications, but it works for us. I have attached the patch file to ENHYDRA_SRCDIR/modules/Core/src/com/lutris/classloader/MultiClassLoader.java. There are only log4j changes in 5.1 tree for this file. Please do comment on the changes if you apply them. Thanks, Srini. --- MultiClassLoader.java Thu May 22 17:03:52 2003 +++ MultiClassLoader.java Fri Nov 14 10:45:58 2003 @@ -291,8 +291,13 @@ * filters to check.*/ private Vector filters = null; + // srini:03 Nov 03-parent class loader is set by the constructor + // and should not be maintained here. I am not sure whether this + // has any issues with the way classloaders are written for + // web-applications, but this change helps us to share objects + // between normal war-applications and enhydra applications. /** Parent class loader, or null if there isn't one. */ - private ClassLoader parentClassLoader; + // private ClassLoader parentClassLoader; /** Secondary class loader, or null if there isn't one. */ private ClassLoader secondaryClassLoader; @@ -303,6 +308,7 @@ * Under Java 1.2, this class is not used. This is a singleton. * <!-- FIXME: delete this when fully 1.2 --> */ +/* since we run on jdk1.2.2 onwards, we dont need this. static class SysClassLoader extends ClassLoader { public Class loadClass(String className, boolean resolve) throws ClassNotFoundException { @@ -319,12 +325,12 @@ return getSystemResourceAsStream(name); } } - +*/ /** Singleton instance of system class loader */ - private static ClassLoader sysClassLoader; + // private static ClassLoader sysClassLoader; /** Method object for accessing 1.2 getSystemClassLoader */ - + /* Use ClassLoader.getSystemClassLoader() instead static { // If the parent has getSystemClassLoader, its 1.2 and we use that // classloader. @@ -341,13 +347,16 @@ throw new FatalExceptionError(except); } } + */ /** * Get the system class loader. */ +/* public static ClassLoader getSystemClassLoader() { return sysClassLoader; } +*/ /** * Constructs class loader with no initial class path and a @@ -364,8 +373,23 @@ public MultiClassLoader(ClassLoader parent, ClassLoader secondary, LogChannel loadLogChannel) { + super(parent); + // srini:03Nov03 - This change means that we cannot run + // this on jdk1.1 anymore. + classPath = new ClassPath(loadLogChannel); + secondaryClassLoader = secondary; + + logChannel = loadLogChannel; + if (logChannel != null) { + logLevel = logChannel.getLevel(LOG_LEVEL); + loggingEnabled = logChannel.isEnabled(logLevel); + } + } + + public MultiClassLoader(ClassLoader secondary, + LogChannel loadLogChannel) { + super(); classPath = new ClassPath(loadLogChannel); - parentClassLoader = parent; secondaryClassLoader = secondary; logChannel = loadLogChannel; @@ -382,7 +406,7 @@ * @param loadLogChannel The log channel, maybe null. */ public MultiClassLoader(LogChannel loadLogChannel) { - this(null, getSystemClassLoader(), loadLogChannel); + this(ClassLoader.getSystemClassLoader(), loadLogChannel); } /** @@ -663,9 +687,9 @@ /** * Set the parent class loader for delegation. */ - public void setParent(ClassLoader parent) { - parentClassLoader = parent; - } + // public void setParent(ClassLoader parent) { + // parentClassLoader = parent; + // } /** * Get the secondary class loader. @@ -922,12 +946,12 @@ cr = new ClassResource(c, resource); loadedClasses.put(className, cr); if (loggingEnabled) { - logChannel.write(logLevel, "class loaded by MultiClassLoader: " + logChannel.write(logLevel, "class loaded by MultiClassLoader(*): " + className); } } if ((cr == null) && loggingEnabled) { - logChannel.write(logLevel, "class not loaded by MultiClassLoader: " + logChannel.write(logLevel, "class not loaded by MultiClassLoader(*): " + className); } return cr; @@ -962,10 +986,10 @@ int filterRestrict = checkFilters(className); // Delegate if parent exists and filter allows. - if ((parentClassLoader != null) + if ((null != getParent()) && (filterRestrict != ClassFilter.CAN_LOAD) && (filterRestrict != ClassFilter.MUST_LOAD)) { - cr = loadClassOther(className, parentClassLoader, "parent"); + cr = loadClassOther(className, getParent(), "parent"); if (cr != null) { return cr; } @@ -1033,9 +1057,9 @@ resource = classPath.getResource(name); if (loggingEnabled) { if (resource == null) { - logChannel.write(logLevel, "getResource not found: " + name); + logChannel.write(logLevel, "getResource not found(*): " + name); } else { - logChannel.write(logLevel, "getResource finished: " + name); + logChannel.write(logLevel, "getResource finished(*): " + name); } } } catch (RuntimeException except) {
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | AW: Xmlc: Compiler problem, Madl Alfred |
|---|---|
| Next by Date: | AW: MultiClassLoader changes, Madl Alfred |
| Previous by Thread: | AW: Xmlc: Compiler problem, Madl Alfred |
| Next by Thread: | AW: MultiClassLoader changes, Madl Alfred |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |