Author: dain
Date: Fri Jun 10 12:37:05 2005
New Revision: 190011
URL: http://svn.apache.org/viewcvs?rev=190011&view=rev
Log:
Moved class loader cleanup code to the configuration class loader itself
Implement doFail in the configuration so it will unload all contained services upon failure
Modified:
geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationClassLoader.java
Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java?rev=190011&r1=190010&r2=190011&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
Fri Jun 10 12:37:05 2005
@@ -23,7 +23,6 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.io.ObjectStreamClass;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
@@ -36,8 +35,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.lang.reflect.Field;
-
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
@@ -48,8 +45,8 @@
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.gbean.GBeanLifecycle;
-import org.apache.geronimo.kernel.ObjectInputStreamExt;
import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.ObjectInputStreamExt;
import org.apache.geronimo.kernel.jmx.JMXUtil;
import org.apache.geronimo.kernel.repository.MissingDependencyException;
import org.apache.geronimo.kernel.repository.Repository;
@@ -363,26 +360,8 @@
log.info("Unable to update persistent state during shutdown", e);
}
- // unregister all GBeans
- for (Iterator i = objectNames.iterator(); i.hasNext();) {
- ObjectName name = (ObjectName) i.next();
- kernel.getDependencyManager().removeDependency(name, objectName);
- try {
- log.trace("Unregistering GBean " + name);
- kernel.unloadGBean(name);
- } catch (Exception e) {
- // ignore
- log.warn("Could not unregister child " + name, e);
- }
- }
-
- // destroy the class loader
- LogFactory.release(configurationClassLoader);
- configurationClassLoader = null;
- clearSoftCache(ObjectInputStream.class, "subclassAudits");
- clearSoftCache(ObjectOutputStream.class, "subclassAudits");
- clearSoftCache(ObjectStreamClass.class, "localDescs");
- clearSoftCache(ObjectStreamClass.class, "reflectors");
+ // shutdown the configuration and unload all beans
+ shutdown();
// update the configuation store
if (configurationStore != null) {
@@ -399,24 +378,29 @@
}
}
- private static void clearSoftCache(Class clazz, String fieldName) {
- Map cache = null;
- try {
- Field f = clazz.getDeclaredField(fieldName);
- f.setAccessible(true);
- cache = (Map) f.get(null);
- } catch (Throwable e) {
- log.error("Unable to clear SoftCache field " + fieldName + " in class " + clazz);
+ private void shutdown() {
+ // unregister all GBeans
+ for (Iterator i = objectNames.iterator(); i.hasNext();) {
+ ObjectName name = (ObjectName) i.next();
+ kernel.getDependencyManager().removeDependency(name, objectName);
+ try {
+ log.trace("Unregistering GBean " + name);
+ kernel.unloadGBean(name);
+ } catch (Exception e) {
+ // ignore
+ log.warn("Could not unregister child " + name, e);
+ }
}
- if (cache != null) {
- synchronized (cache) {
- cache.clear();
- }
+ // destroy the class loader
+ if (configurationClassLoader != null) {
+ configurationClassLoader.destroy();
+ configurationClassLoader = null;
}
}
public void doFail() {
+ shutdown();
}
/**
Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationClassLoader.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationClassLoader.java?rev=190011&r1=190010&r2=190011&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationClassLoader.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationClassLoader.java
Fri Jun 10 12:37:05 2005
@@ -20,6 +20,13 @@
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+import java.util.Map;
+import java.lang.reflect.Field;
+
+import org.apache.commons.logging.LogFactory;
/**
*
@@ -45,8 +52,40 @@
public void setClassLoaderServerURLs(URL[] urls) {
this.urls = urls;
}
-
+
+ public void destroy() {
+ LogFactory.release(this);
+ clearSoftCache(ObjectInputStream.class, "subclassAudits");
+ clearSoftCache(ObjectOutputStream.class, "subclassAudits");
+ clearSoftCache(ObjectStreamClass.class, "localDescs");
+ clearSoftCache(ObjectStreamClass.class, "reflectors");
+ }
+
public String toString() {
return "[Configuration ClassLoader id=" + id + "]";
+ }
+
+ private static Object lock = new Object();
+ private static boolean clearSoftCacheFailed = false;
+ private static void clearSoftCache(Class clazz, String fieldName) {
+ Map cache = null;
+ try {
+ Field f = clazz.getDeclaredField(fieldName);
+ f.setAccessible(true);
+ cache = (Map) f.get(null);
+ } catch (Throwable e) {
+ synchronized (lock) {
+ if (!clearSoftCacheFailed) {
+ clearSoftCacheFailed = true;
+ LogFactory.getLog(ConfigurationClassLoader.class).error("Unable to clear
SoftCache field " + fieldName + " in class " + clazz);
+ }
+ }
+ }
+
+ if (cache != null) {
+ synchronized (cache) {
+ cache.clear();
+ }
+ }
}
}
|