You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by xu...@apache.org on 2012/04/11 18:09:46 UTC
svn commit: r1324838 - in
/geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo:
gbean/runtime/GBeanInstanceState.java
kernel/osgi/ConfigurationActivator.java kernel/osgi/KernelActivator.java
Author: xuhaihong
Date: Wed Apr 11 16:09:46 2012
New Revision: 1324838
URL: http://svn.apache.org/viewvc?rev=1324838&view=rev
Log:
Stop the child GBeans in the configuration in order while shutdown the server
Modified:
geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java
geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/ConfigurationActivator.java
geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/KernelActivator.java
Modified: geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java?rev=1324838&r1=1324837&r2=1324838&view=diff
==============================================================================
--- geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java (original)
+++ geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java Wed Apr 11 16:09:46 2012
@@ -16,18 +16,18 @@
*/
package org.apache.geronimo.gbean.runtime;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Iterator;
+import java.util.Set;
+
import org.apache.geronimo.gbean.AbstractName;
import org.apache.geronimo.kernel.DependencyManager;
import org.apache.geronimo.kernel.GBeanNotFoundException;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.management.State;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.Iterator;
-import java.util.Set;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @version $Rev$ $Date$
@@ -173,9 +173,9 @@ public class GBeanInstanceState
// Don't try to stop dependents from within a synchronized block... this should reduce deadlocks
// stop all of my dependent objects
- Set dependents = dependencyManager.getChildren(abstractName);
- for (Iterator iterator = dependents.iterator(); iterator.hasNext();) {
- AbstractName child = (AbstractName) iterator.next();
+ Set<AbstractName> dependents = dependencyManager.getChildren(abstractName);
+ for (Iterator<AbstractName> iterator = dependents.iterator(); iterator.hasNext();) {
+ AbstractName child = iterator.next();
try {
log.trace("Checking if child is running: child={}", child);
if (kernel.getGBeanState(child) == State.RUNNING_INDEX) {
Modified: geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/ConfigurationActivator.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/ConfigurationActivator.java?rev=1324838&r1=1324837&r2=1324838&view=diff
==============================================================================
--- geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/ConfigurationActivator.java (original)
+++ geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/ConfigurationActivator.java Wed Apr 11 16:09:46 2012
@@ -21,28 +21,38 @@
package org.apache.geronimo.kernel.osgi;
import java.io.InputStream;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.ServiceReference;
-import org.apache.geronimo.kernel.config.ConfigurationUtil;
-import org.apache.geronimo.kernel.config.ConfigurationData;
-import org.apache.geronimo.kernel.config.ConfigurationManager;
-import org.apache.geronimo.kernel.config.Configuration;
-import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.kernel.GBeanNotFoundException;
import org.apache.geronimo.kernel.InternalKernelException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.config.Configuration;
+import org.apache.geronimo.kernel.config.ConfigurationData;
+import org.apache.geronimo.kernel.config.ConfigurationManager;
+import org.apache.geronimo.kernel.config.ConfigurationUtil;
import org.apache.geronimo.kernel.repository.Artifact;
-import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.kernel.util.CircularReferencesException;
+import org.apache.geronimo.kernel.util.IllegalNodeConfigException;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @version $Rev$ $Date$
*/
public class ConfigurationActivator implements BundleActivator {
- private Artifact id;
+ private static final Logger logger = LoggerFactory.getLogger(ConfigurationActivator.class);
+ private Artifact id;
public void start(BundleContext bundleContext) throws Exception {
ServiceReference kernelReference = null;
@@ -84,6 +94,15 @@ public class ConfigurationActivator impl
return;
}
Kernel kernel = (Kernel) bundleContext.getService(kernelReference);
+ //Stop the child configurations and child GBeans, the stopRecursive method is the same with KernelConfigurationManager
+ //In this method, we will pre-sort the child GBeans before stopping them, with that, those GBeans could be stopped in order
+ //Or it is possible to get the error message [GBeanDependency] Illegal state: current target for a single valued reference stopped
+ ConfigurationManager manager = ConfigurationUtil.getConfigurationManager(kernel);
+ Configuration configuration = manager.getConfiguration(id);
+ if(configuration != null) {
+ stopRecursive(kernel, configuration);
+ }
+
AbstractName name = Configuration.getConfigurationAbstractName(id);
//TODO investigate how this is called and whether just stopping/unloading the configuration gbean will
//leave the configuration model in a consistent state. We might need a shutdown flag set elsewhere to avoid
@@ -113,4 +132,47 @@ public class ConfigurationActivator impl
}
}
}
+
+ private void stopRecursive(Kernel kernel , Configuration configuration) {
+ // stop all of the child configurations first
+ for (Iterator<Configuration> iterator = configuration.getChildren().iterator(); iterator.hasNext();) {
+ Configuration childConfiguration = iterator.next();
+ stopRecursive(kernel, childConfiguration);
+ }
+ Collection<GBeanData> gbeans;
+ try {
+ List<GBeanData> sortedGBeans = ConfigurationUtil.sortGBeanDataByDependency(configuration.getGBeans().values());
+ Collections.reverse(sortedGBeans);
+ gbeans = sortedGBeans;
+ } catch (IllegalNodeConfigException e) {
+ gbeans = configuration.getGBeans().values();
+ } catch (CircularReferencesException e) {
+ gbeans = configuration.getGBeans().values();
+ }
+ // stop the gbeans
+ for (Iterator<GBeanData> iterator = gbeans.iterator(); iterator.hasNext();) {
+ GBeanData gbeanData = iterator.next();
+ AbstractName gbeanName = gbeanData.getAbstractName();
+ try {
+ kernel.stopGBean(gbeanName);
+ } catch (GBeanNotFoundException ignored) {
+ } catch (IllegalStateException ignored) {
+ } catch (InternalKernelException kernelException) {
+ logger.debug("Error cleaning up after failed start of configuration " + configuration.getId() + " gbean " + gbeanName, kernelException);
+ }
+ }
+
+ // unload the gbeans
+ for (Iterator<GBeanData> iterator = gbeans.iterator(); iterator.hasNext();) {
+ GBeanData gbeanData = iterator.next();
+ AbstractName gbeanName = gbeanData.getAbstractName();
+ try {
+ kernel.unloadGBean(gbeanName);
+ } catch (GBeanNotFoundException ignored) {
+ } catch (IllegalStateException ignored) {
+ } catch (InternalKernelException kernelException) {
+ logger.debug("Error cleaning up after failed start of configuration " + configuration.getId() + " gbean " + gbeanName, kernelException);
+ }
+ }
+ }
}
Modified: geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/KernelActivator.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/KernelActivator.java?rev=1324838&r1=1324837&r2=1324838&view=diff
==============================================================================
--- geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/KernelActivator.java (original)
+++ geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/KernelActivator.java Wed Apr 11 16:09:46 2012
@@ -20,29 +20,19 @@
package org.apache.geronimo.kernel.osgi;
-import java.util.Dictionary;
-import java.util.Set;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.LinkedHashSet;
-import java.net.URL;
import java.io.InputStream;
-import java.io.IOException;
+import java.net.URL;
+import java.util.Dictionary;
+import org.apache.geronimo.gbean.AbstractName;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.KernelFactory;
-import org.apache.geronimo.kernel.repository.Artifact;
import org.apache.geronimo.kernel.config.ConfigurationData;
import org.apache.geronimo.kernel.config.ConfigurationUtil;
-import org.apache.geronimo.kernel.config.PersistentConfigurationList;
-import org.apache.geronimo.kernel.config.ConfigurationManager;
-import org.apache.geronimo.kernel.config.InvalidConfigException;
-import org.apache.geronimo.gbean.AbstractName;
-import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
-import org.osgi.framework.Bundle;
/**
* @version $Rev$ $Date$