1 17 18 package org.apache.geronimo.kernel.config; 19 20 import java.net.URI ; 21 import java.net.URL ; 22 import java.net.URLClassLoader ; 23 import java.io.ObjectInputStream ; 24 import java.io.ObjectOutputStream ; 25 import java.io.ObjectStreamClass ; 26 import java.util.Map ; 27 import java.lang.reflect.Field ; 28 29 import org.apache.commons.logging.LogFactory; 30 31 35 public class ConfigurationClassLoader extends URLClassLoader { 36 private final URI id; 37 38 public ConfigurationClassLoader(URI id, URL [] urls, ClassLoader parent) { 39 super(urls, parent); 40 this.id = id; 41 } 42 43 public URI getID() { 44 return id; 45 } 46 47 public void destroy() { 48 LogFactory.release(this); 49 clearSoftCache(ObjectInputStream .class, "subclassAudits"); 50 clearSoftCache(ObjectOutputStream .class, "subclassAudits"); 51 clearSoftCache(ObjectStreamClass .class, "localDescs"); 52 clearSoftCache(ObjectStreamClass .class, "reflectors"); 53 } 54 55 public String toString() { 56 return "[Configuration ClassLoader id=" + id + "]"; 57 } 58 59 private static Object lock = new Object (); 60 private static boolean clearSoftCacheFailed = false; 61 private static void clearSoftCache(Class clazz, String fieldName) { 62 Map cache = null; 63 try { 64 Field f = clazz.getDeclaredField(fieldName); 65 f.setAccessible(true); 66 cache = (Map ) f.get(null); 67 } catch (Throwable e) { 68 synchronized (lock) { 69 if (!clearSoftCacheFailed) { 70 clearSoftCacheFailed = true; 71 LogFactory.getLog(ConfigurationClassLoader.class).debug("Unable to clear SoftCache field " + fieldName + " in class " + clazz); 72 } 73 } 74 } 75 76 if (cache != null) { 77 synchronized (cache) { 78 cache.clear(); 79 } 80 } 81 } 82 } 83 | Popular Tags |