Author: dain
Date: Mon Mar 6 03:35:35 2006
New Revision: 383519
URL: http://svn.apache.org/viewcvs?rev=383519&view=rev
Log:
Configuration manager now does recursive load and start counting.
Start is currently not recursive due to problems in deployment from the packaging plugin.
Shutdown causes dead proxy exceptions.
Modified:
geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/configmanager/ConfigManagerPortlet.java
geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/RedeployCommand.java
geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/StartCommand.java
geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
geronimo/branches/1.1/modules/jetty-builder/src/test/org/apache/geronimo/jetty/deployment/JettyModuleBuilderTest.java
geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManager.java
geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManagerImpl.java
geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationUtil.java
geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/log/GeronimoLogging.java
geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/config/ConfigurationManagerTest.java
geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationDump.java
geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/logging/log4j/Log4jService.java
geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/CommandLine.java
geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java
geronimo/branches/1.1/modules/tomcat-builder/src/test/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilderTest.java
geronimo/branches/1.1/plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/StartServer.java
Modified: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/configmanager/ConfigManagerPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/configmanager/ConfigManagerPortlet.java?rev=383519&r1=383518&r2=383519&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/configmanager/ConfigManagerPortlet.java (original)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/configmanager/ConfigManagerPortlet.java Mon Mar 6 03:35:35 2006
@@ -101,11 +101,8 @@
Artifact configID = Artifact.create(config);
if (START_ACTION.equals(action)) {
- List ancestors = configurationManager.loadConfiguration(configID);
- for (Iterator it = ancestors.iterator(); it.hasNext();) {
- Artifact ancestor = (Artifact) it.next();
- configurationManager.startConfiguration(ancestor);
- }
+ configurationManager.loadConfiguration(configID);
+ configurationManager.startConfiguration(configID);
messageStatus = "Started application<br /><br />";
} else if (STOP_ACTION.equals(action)) {
configurationManager.stopConfiguration(configID);
Modified: geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/RedeployCommand.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/RedeployCommand.java?rev=383519&r1=383518&r2=383519&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/RedeployCommand.java (original)
+++ geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/RedeployCommand.java Mon Mar 6 03:35:35 2006
@@ -34,7 +34,6 @@
import java.io.File;
import java.io.InputStream;
import java.net.URI;
-import java.util.List;
/**
* @version $Rev$ $Date$
@@ -107,12 +106,9 @@
doDeploy(module.getTarget(), false);
updateStatus("Deployed "+configID);
- List list = configurationManager.loadConfiguration(configID);
- for (int j = 0; j < list.size(); j++) {
- Artifact name = (Artifact) list.get(j);
- configurationManager.startConfiguration(name);
- updateStatus("Started " + name);
- }
+ configurationManager.loadConfiguration(configID);
+ configurationManager.startConfiguration(configID);
+ updateStatus("Started " + configID);
}
} finally {
ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager);
Modified: geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/StartCommand.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/StartCommand.java?rev=383519&r1=383518&r2=383519&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/StartCommand.java (original)
+++ geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/StartCommand.java Mon Mar 6 03:35:35 2006
@@ -67,11 +67,12 @@
}
// Load and start the module
- List list = configurationManager.loadConfiguration(moduleID);
- for (int j = 0; j < list.size(); j++) {
- Artifact name = (Artifact) list.get(j);
- configurationManager.startConfiguration(name);
- String configName = name.toString();
+ Configuration configuration = configurationManager.loadConfiguration(moduleID);
+ // todo review this -- start is recursive, but this is doing more than a recursive start
+// for (int j = 0; j < list.size(); j++) {
+// Artifact name = (Artifact) list.get(j);
+ configurationManager.startConfiguration(configuration);
+ String configName = configuration.getObjectName();
List kids = loadChildren(kernel, configName);
TargetModuleIDImpl id = new TargetModuleIDImpl(modules[i].getTarget(), configName,
(String[]) kids.toArray(new String[kids.size()]));
@@ -87,7 +88,7 @@
}
}
addModule(id);
- }
+// }
}
} finally {
ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager);
Modified: geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java?rev=383519&r1=383518&r2=383519&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java (original)
+++ geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java Mon Mar 6 03:35:35 2006
@@ -59,7 +59,7 @@
import org.apache.geronimo.kernel.config.ConfigurationStore;
import org.apache.geronimo.kernel.config.ConfigurationUtil;
import org.apache.geronimo.kernel.config.InvalidConfigException;
-import org.apache.geronimo.kernel.management.State;
+import org.apache.geronimo.kernel.config.NoSuchConfigException;
import org.apache.geronimo.kernel.repository.Artifact;
import org.apache.geronimo.kernel.repository.ArtifactResolver;
import org.apache.geronimo.kernel.repository.DefaultArtifactResolver;
@@ -80,8 +80,7 @@
private final File baseDir;
private final URI baseUri;
private final byte[] buffer = new byte[4096];
- private final List loadedAncestors = new ArrayList();
- private final List startedAncestors = new ArrayList();
+ private final List loadedConfigurations = new ArrayList();
private final List childConfigurationDatas = new ArrayList();
@@ -448,36 +447,20 @@
if (kernel != null && parentId != null && parentId.size() > 0) {
ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
try {
- loadAncestors(kernel, parentId, loadedAncestors, configurationManager);
-// ParentSource parentSource = new ConfigurationParentSource(kernel);
-// parentId = getExtremalSet(parentId, parentSource);
-// environment.setImports(parentId);
-
- try {
- for (Iterator iterator = parentId.iterator(); iterator.hasNext();) {
- Artifact artifact = (Artifact) iterator.next();
- List started = new ArrayList();
- startAncestors(artifact, kernel, started, configurationManager);
- startedAncestors.addAll(started);
- }
- } catch (DeploymentException e) {
- throw e;
- } catch (Exception e) {
- throw new DeploymentException(e);
- }
+ loadConfigurations(parentId, configurationManager);
} finally {
ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager);
}
}
}
- private void loadAncestors(Kernel kernel, Collection parentId, List loadedAncestors, ConfigurationManager configurationManager) throws DeploymentException {
- if (kernel != null && parentId != null) {
+ private void loadConfigurations(Collection configurations, ConfigurationManager configurationManager) throws DeploymentException {
+ if (configurationManager != null && configurations != null) {
try {
- for (Iterator iterator = parentId.iterator(); iterator.hasNext();) {
+ for (Iterator iterator = configurations.iterator(); iterator.hasNext();) {
Artifact artifact = (Artifact) iterator.next();
- List newAncestors = configurationManager.loadConfiguration(artifact);
- loadedAncestors.addAll(newAncestors);
+ configurationManager.loadConfiguration(artifact);
+ loadedConfigurations.add(artifact);
}
} catch (Exception e) {
throw new DeploymentException("Unable to load parents", e);
@@ -485,24 +468,6 @@
}
}
- private void startAncestors(Artifact configID, Kernel kernel, List started, ConfigurationManager configurationManager) throws Exception {
- if (configID != null) {
- ObjectName configName = Configuration.getConfigurationObjectName(configID);
- if (!isRunning(kernel, configName)) {
- LinkedHashSet patterns = ((Environment) kernel.getAttribute(configName, "environment")).getImports();
- for (Iterator iterator = patterns.iterator(); iterator.hasNext();) {
- Artifact pattern = (Artifact) iterator.next();
- startAncestors(pattern, kernel, started, configurationManager);
- }
- started.add(configID);
- }
- }
- }
-
- private static boolean isRunning(Kernel kernel, ObjectName name) throws Exception {
- return State.RUNNING_INDEX == kernel.getGBeanState(name);
- }
-
public ClassLoader getClassLoader(Repository repository) throws DeploymentException {
return getClassLoader(repository, null);
}
@@ -590,7 +555,7 @@
if (kernel != null) {
ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
try {
- startedAncestors.clear();
+// startedAncestors.clear();
//TODO configid WE NEED REFERENCE COUNTING ON THIS STUFF!!!
//right now it is impossible to deploy 2 app clients in an ear.
// Collections.reverse(loadedAncestors);
@@ -606,7 +571,14 @@
}
}
*/
- loadedAncestors.clear();
+ for (Iterator iterator = loadedConfigurations.iterator(); iterator.hasNext();) {
+ Artifact artifact = (Artifact) iterator.next();
+ try {
+ configurationManager.unloadConfiguration(artifact);
+ } catch (NoSuchConfigException ignored) {
+ }
+ }
+ loadedConfigurations.clear();
} finally {
ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager);
}
Modified: geronimo/branches/1.1/modules/jetty-builder/src/test/org/apache/geronimo/jetty/deployment/JettyModuleBuilderTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/jetty-builder/src/test/org/apache/geronimo/jetty/deployment/JettyModuleBuilderTest.java?rev=383519&r1=383518&r2=383519&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/jetty-builder/src/test/org/apache/geronimo/jetty/deployment/JettyModuleBuilderTest.java (original)
+++ geronimo/branches/1.1/modules/jetty-builder/src/test/org/apache/geronimo/jetty/deployment/JettyModuleBuilderTest.java Mon Mar 6 03:35:35 2006
@@ -150,6 +150,7 @@
//what is this testing?
configuration = configurationManager.loadConfiguration(earContext.getConfigurationData(), configurationStore);
+ configurationManager.startConfiguration(configuration);
configurationManager.stopConfiguration(configuration);
configurationManager.unloadConfiguration(configuration);
}
Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java?rev=383519&r1=383518&r2=383519&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java Mon Mar 6 03:35:35 2006
@@ -95,6 +95,9 @@
public class Configuration implements GBeanLifecycle, ConfigurationParent {
private static final Log log = LogFactory.getLog(Configuration.class);
+ /**
+ * @deprecated Use artifact version of this method
+ */
public static ObjectName getConfigurationObjectName(URI configId) throws MalformedObjectNameException {
return new ObjectName("geronimo.config:name=" + ObjectName.quote(configId.toString()));
}
@@ -274,11 +277,6 @@
} finally {
ois.close();
}
-
- // todo consider applying updates from attribute store
- // if (attributeStore != null) {
- // gbeans = attributeStore.setAttributes(environment.getConfigId(), gbeans, configurationClassLoader);
- //}
} catch (Exception e) {
throw new InvalidConfigException("Unable to deserialize GBeanState", e);
} finally {
Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManager.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManager.java?rev=383519&r1=383518&r2=383519&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManager.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManager.java Mon Mar 6 03:35:35 2006
@@ -61,7 +61,7 @@
* @throws IOException if there is a problem loading te configuration from the store
* @throws InvalidConfigException if the configuration is corrupt
*/
- List loadConfiguration(Artifact configID) throws NoSuchConfigException, IOException, InvalidConfigException;
+ Configuration loadConfiguration(Artifact configID) throws NoSuchConfigException, IOException, InvalidConfigException;
Configuration loadConfiguration(ConfigurationData configurationData) throws NoSuchConfigException, IOException, InvalidConfigException;
Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManagerImpl.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManagerImpl.java?rev=383519&r1=383518&r2=383519&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManagerImpl.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManagerImpl.java Mon Mar 6 03:35:35 2006
@@ -44,12 +44,13 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
-import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
import java.net.URL;
import java.net.URI;
import java.net.MalformedURLException;
@@ -64,6 +65,7 @@
*/
public class ConfigurationManagerImpl implements ConfigurationManager, GBeanLifecycle {
private static final Log log = LogFactory.getLog(ConfigurationManagerImpl.class);
+
protected final Kernel kernel;
private final Collection stores;
protected final ManageableAttributeStore attributeStore;
@@ -72,15 +74,7 @@
private final ArtifactManager artifactManager;
private final ArtifactResolver artifactResolver;
private final ClassLoader classLoader;
- private static final ObjectName CONFIGURATION_NAME_QUERY;
-
- static {
- try {
- CONFIGURATION_NAME_QUERY = new ObjectName("geronimo.config:*");
- } catch (MalformedObjectNameException e) {
- throw new RuntimeException("could not create object name... bug", e);
- }
- }
+ private final Map configurations = new LinkedHashMap();
public ConfigurationManagerImpl(Kernel kernel,
Collection stores,
@@ -125,35 +119,35 @@
throw new NoSuchStoreException("No such store: " + storeName);
}
- public Configuration getConfiguration(Artifact configId) {
- try {
- ObjectName objectName = Configuration.getConfigurationObjectName(configId);
- Configuration configuration = (Configuration) kernel.getProxyManager().createProxy(objectName, Configuration.class);
- return configuration;
- } catch (InvalidConfigException e) {
- return null;
- }
+ public Configuration getConfiguration(Artifact configurationId) {
+ ConfigurationStatus configurationStatus = (ConfigurationStatus) configurations.get(configurationId);
+ return configurationStatus.getConfiguration();
}
public boolean isLoaded(Artifact configId) {
- try {
- ObjectName configurationName = Configuration.getConfigurationObjectName(configId);
- return State.RUNNING_INDEX == kernel.getGBeanState(configurationName);
- } catch (Exception e) {
- return false;
- }
+ return configurations.containsKey(configId);
}
- public List loadConfiguration(Artifact configID) throws NoSuchConfigException, IOException, InvalidConfigException {
- if (isLoaded(configID)) {
- return Collections.EMPTY_LIST;
+ public Configuration loadConfiguration(Artifact configurationId) throws NoSuchConfigException, IOException, InvalidConfigException {
+ ConfigurationStatus configurationStatus = (ConfigurationStatus) configurations.get(configurationId);
+ if (configurationStatus != null) {
+ // already loaded, so just update the load count
+ configurationStatus.load();
+ return configurationStatus.getConfiguration();
+ } else if (kernel.isLoaded(Configuration.getConfigurationObjectName(configurationId))) {
+ // hack
+ Configuration configuration = (Configuration) kernel.getProxyManager().createProxy(Configuration.getConfigurationObjectName(configurationId), Configuration.class);
+ configurationStatus = new ConfigurationStatus(configuration, getParentStatuses(configuration));
+ configurationStatus.load();
+ configurations.put(configurationId, configurationStatus);
+ return configurationStatus.getConfiguration();
}
// load the GBeanData for the new configuration
- GBeanData gbeanData = loadConfigurationGBeanData(configID);
+ GBeanData gbeanData = loadConfigurationGBeanData(configurationId);
// load the configuration
- return loadConfiguration(configID, gbeanData);
+ return loadConfiguration(gbeanData);
}
public Configuration loadConfiguration(ConfigurationData configurationData) throws NoSuchConfigException, IOException, InvalidConfigException {
@@ -161,93 +155,132 @@
}
public Configuration loadConfiguration(ConfigurationData configurationData, ConfigurationStore configurationStore) throws NoSuchConfigException, IOException, InvalidConfigException {
- Artifact id = configurationData.getId();
try {
GBeanData gbeanData = ConfigurationUtil.toConfigurationGBeanData(configurationData, configurationStore);
- loadConfiguration(id, gbeanData);
- Configuration configuration = getConfiguration(id);
- return configuration;
+ return loadConfiguration(gbeanData);
} catch (MalformedObjectNameException e) {
throw new InvalidConfigException(e);
}
}
- private List loadConfiguration(Artifact configID, GBeanData gbeanData) throws NoSuchConfigException, IOException, InvalidConfigException {
- Set preloaded = kernel.listGBeans(CONFIGURATION_NAME_QUERY);
- for (Iterator it = preloaded.iterator(); it.hasNext();) {
- ObjectName name = (ObjectName) it.next();
- try {
- if (kernel.getGBeanState(name) != State.RUNNING_INDEX) {
- it.remove();
- }
- } catch (GBeanNotFoundException e) {
- it.remove();
- }
+ private Configuration loadConfiguration(GBeanData gbeanData) throws NoSuchConfigException, IOException, InvalidConfigException {
+ Artifact id = getConfigurationId(gbeanData);
+ if (configurations.containsKey(id)) {
+ // already loaded, so just update the load count
+ ConfigurationStatus configurationStatus = (ConfigurationStatus) configurations.get(id);
+ configurationStatus.load();
+ return configurationStatus.getConfiguration();
}
// load configurations from the new child to the parents
- LinkedList ancestors = new LinkedList();
- loadRecursive(configID, gbeanData, ancestors, preloaded);
+ LinkedHashMap unloadedConfigurations = new LinkedHashMap();
+ loadDepthFirst(gbeanData, unloadedConfigurations);
- // start the unloaded configurations from the prents to the chidren
- List parentToChild = new LinkedList(ancestors);
- for (Iterator iterator = parentToChild.iterator(); iterator.hasNext();) {
- Artifact parent = (Artifact) iterator.next();
- ObjectName configurationName = Configuration.getConfigurationObjectName(parent);
+ // load and start the unloaded configurations depth first
+ Map loadedConfigurations = new LinkedHashMap(unloadedConfigurations.size());
+ try {
+ for (Iterator iterator = unloadedConfigurations.entrySet().iterator(); iterator.hasNext();) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ Artifact configurationId = (Artifact) entry.getKey();
+ GBeanData configurationData = (GBeanData) entry.getValue();
+ ObjectName configurationName = Configuration.getConfigurationObjectName(configurationId);
- // start configuration and assure it started
- try {
- kernel.startGBean(configurationName);
- if (State.RUNNING_INDEX != kernel.getGBeanState(configurationName)) {
- throw new InvalidConfigurationException("Configuration " + parent + " failed to start");
+ // load the configuation
+ try {
+ kernel.loadGBean(configurationData, classLoader);
+ } catch (GBeanAlreadyExistsException e) {
+ throw new InvalidConfigException("Unable to load configuration gbean " + configurationId, e);
}
- } catch (InvalidConfigurationException e) {
- throw e;
- } catch (GBeanNotFoundException e) {
- throw new InvalidConfigException("Unable to start configuration gbean", e);
+
+ // start the configuration and assure it started
+ Configuration configuration;
+ try {
+ kernel.startGBean(configurationName);
+ if (State.RUNNING_INDEX != kernel.getGBeanState(configurationName)) {
+ throw new InvalidConfigurationException("Configuration " + configurationId + " failed to start");
+ }
+
+ // create a proxy to the configuration
+ configuration = (Configuration) kernel.getProxyManager().createProxy(configurationName, Configuration.class);
+ loadedConfigurations.put(configurationId, configuration);
+ log.debug("Loaded Configuration " + configurationName);
+ } catch (Exception e) {
+ safeConfigurationUnload(configurationId);
+ if (e instanceof InvalidConfigException) {
+ throw (InvalidConfigException) e;
+ }
+ throw new InvalidConfigException("Unable to start configuration gbean " + configurationId, e);
+ }
+
+ // todo move this to startConfiguration when deployment code has been update to not search kernel
+ registerGBeans(configuration);
+ }
+ } catch (Exception e) {
+ for (Iterator iterator = loadedConfigurations.keySet().iterator(); iterator.hasNext();) {
+ Artifact configurationId = (Artifact) iterator.next();
+ safeConfigurationUnload(configurationId);
}
+ if (e instanceof InvalidConfigException) {
+ throw (InvalidConfigException) e;
+ }
+ throw new InvalidConfigException("Unable to start configuration gbean " + id, e);
+ }
- log.debug("Loaded Configuration " + configurationName);
+ // update the status of the loaded configurations
+ for (Iterator iterator = loadedConfigurations.values().iterator(); iterator.hasNext();) {
+ Configuration configuration = (Configuration) iterator.next();
- // todo move this to startConfiguration when deployment code has been update to not search kernel
- Configuration configuration = (Configuration) kernel.getProxyManager().createProxy(configurationName, Configuration.class);
- registerGBeans(configuration);
+ List parentStatuses = getParentStatuses(configuration);
+ ConfigurationStatus configurationStatus = new ConfigurationStatus(configuration, parentStatuses);
+ configurations.put(getConfigurationId(configuration), configurationStatus);
}
- // todo clean up after failure
- return ancestors;
+ ConfigurationStatus configurationStatus = (ConfigurationStatus) configurations.get(id);
+ configurationStatus.load();
+ return configurationStatus.getConfiguration();
}
- private void loadRecursive(Artifact configId, GBeanData gbeanData, LinkedList ancestors, Set preloaded) throws NoSuchConfigException, IOException, InvalidConfigException {
- try {
- ObjectName name = Configuration.getConfigurationObjectName(configId);
- if (preloaded.contains(name)) {
- return;
+ private List getParentStatuses(Configuration configuration) {
+ List parents = configuration.getParents();
+ List parentStatuses = new ArrayList(parents.size());
+ for (Iterator iterator1 = parents.iterator(); iterator1.hasNext();) {
+ Configuration parent = (Configuration) iterator1.next();
+ Artifact parentId = getConfigurationId(parent);
+ ConfigurationStatus parentStatus = (ConfigurationStatus) configurations.get(parentId);
+ if (parentStatus == null) {
+ throw new IllegalStateException("Parent status not found " + parentId);
}
- preprocess(gbeanData);
+ parentStatuses.add(parentStatus);
+ }
+ return parentStatuses;
+ }
- try {
- kernel.loadGBean(gbeanData, classLoader);
- } catch (Exception e) {
- throw new InvalidConfigException("Unable to register configuration", e);
- }
-
- log.debug("Loaded Configuration " + configId);
-
- //put the earliest ancestors first, even if we have already started them.
- ancestors.remove(configId);
- ancestors.addFirst(configId);
-
- Environment environment = (Environment) kernel.getAttribute(name, "environment");
- for (Iterator iterator = environment.getImports().iterator(); iterator.hasNext();) {
- Artifact parent = (Artifact) iterator.next();
- if (!isLoaded(parent)) {
- GBeanData parentGBeanData = loadConfigurationGBeanData(parent);
- loadRecursive(parent, parentGBeanData, ancestors, preloaded);
+ private Artifact getConfigurationId(GBeanData gbeanData) {
+ Environment environment = (Environment) gbeanData.getAttribute("environment");
+ return environment.getConfigId();
+ }
+
+ private void loadDepthFirst(GBeanData gbeanData, LinkedHashMap unloadedConfigurations) throws NoSuchConfigException, IOException, InvalidConfigException {
+ try {
+ // if this parent hasn't already been processed, iterate into the parent
+ Artifact configurationId = getConfigurationId(gbeanData);
+ if (!unloadedConfigurations.containsKey(configurationId)) {
+ preprocess(gbeanData);
+
+ Environment environment = (Environment) gbeanData.getAttribute("environment");
+ for (Iterator iterator = environment.getImports().iterator(); iterator.hasNext();) {
+ Artifact parentId = (Artifact) iterator.next();
+ if (!configurations.containsKey(parentId)) {
+ GBeanData parentGBeanData = loadConfigurationGBeanData(parentId);
+ loadDepthFirst(parentGBeanData, unloadedConfigurations);
+ }
}
}
+
+ // depth first - all unloaded parents have been added, not add this configuration
+ unloadedConfigurations.put(configurationId, gbeanData);
} catch (NoSuchConfigException e) {
throw e;
} catch (IOException e) {
@@ -319,11 +352,37 @@
gbeanData.setReferencePatterns("Parents", importNames);
}
+ private void safeConfigurationUnload(Artifact configurationId) {
+ ObjectName configurationName;
+ try {
+ configurationName = Configuration.getConfigurationObjectName(configurationId);
+ } catch (InvalidConfigException e) {
+ throw new AssertionError(e);
+ }
+
+ // unload this configuration
+ try {
+ kernel.stopGBean(configurationName);
+ } catch (GBeanNotFoundException ignored) {
+ // Good
+ } catch (Exception stopException) {
+ log.warn("Unable to stop failed configuration: " + configurationId, stopException);
+ }
+
+ try {
+ kernel.unloadGBean(configurationName);
+ } catch (GBeanNotFoundException ignored) {
+ // Good
+ } catch (Exception unloadException) {
+ log.warn("Unable to unload failed configuration: " + configurationId, unloadException);
+ }
+ }
+
private void registerGBeans(Configuration configuration) throws InvalidConfigException, NoSuchConfigException, MalformedURLException {
// load the attribute overrides from the attribute store
Collection gbeans = configuration.getGBeans().values();
if (attributeStore != null) {
- gbeans = attributeStore.setAttributes(configuration.getId(), gbeans, configuration.getConfigurationClassLoader());
+ gbeans = attributeStore.setAttributes(getConfigurationId(configuration), gbeans, configuration.getConfigurationClassLoader());
}
// register all the GBeans
@@ -338,12 +397,12 @@
// todo remove this when web app cl are config. cl.
GAttributeInfo attribute = gbeanData.getGBeanInfo().getAttribute("configurationBaseUrl");
if (attribute != null && attribute.getType().equals("java.net.URL")) {
- URL baseURL = configurationStore.resolve(configuration.getId(), URI.create(""));
+ URL baseURL = configurationStore.resolve(getConfigurationId(configuration), URI.create(""));
gbeanData.setAttribute("configurationBaseUrl", baseURL);
}
// add a dependency from the gbean to the configuration
- gbeanData.getDependencies().add(Configuration.getConfigurationObjectName(configuration.getId()));
+ gbeanData.getDependencies().add(Configuration.getConfigurationObjectName(getConfigurationId(configuration)));
log.trace("Registering GBean " + gbeanData.getName());
@@ -355,20 +414,26 @@
}
}
- public void startConfiguration(Artifact configId) throws InvalidConfigException {
- if (!isLoaded(configId)) {
- throw new InvalidConfigurationException("Configuration " + configId + " failed to start");
+ public void startConfiguration(Configuration configuration) throws InvalidConfigException {
+ startConfiguration(getConfigurationId(configuration));
+ }
+ public void startConfiguration(Artifact id) throws InvalidConfigException {
+ ConfigurationStatus configurationStatus = (ConfigurationStatus) configurations.get(id);
+ if (configurationStatus == null) {
+ throw new InvalidConfigurationException("Configuration is not loaded " + id);
}
- Configuration configuration = getConfiguration(configId);
- startConfiguration(configuration);
+ // todo recursion disabled
+ List startList = configurationStatus.start();
+ start(configurationStatus.getConfiguration());
+// for (Iterator iterator = startList.iterator(); iterator.hasNext();) {
+// Configuration configuration = (Configuration) iterator.next();
+// start(configuration);
+// }
+// // todo clean up after failure
}
- public void startConfiguration(Configuration configuration) throws InvalidConfigException {
- if (!isLoaded(configuration.getId())) {
- throw new InvalidConfigurationException("Configuration " + configuration.getId() + " failed to start");
- }
-
+ public void start(Configuration configuration) throws InvalidConfigException {
// todo move this from loadConfiguration when deployment code has been update to not search kernel
// registerGBeans(configuration);
@@ -383,34 +448,46 @@
}
// assure all of the gbeans are started
- for (Iterator iterator = gbeans.keySet().iterator(); iterator.hasNext();) {
- ObjectName gbeanName = (ObjectName) iterator.next();
- if (State.RUNNING_INDEX != kernel.getGBeanState(gbeanName)) {
- throw new InvalidConfigurationException("Configuration " + configuration.getId() + " failed to start because gbean " + gbeanName + " did not start");
- }
- }
+// for (Iterator iterator = gbeans.keySet().iterator(); iterator.hasNext();) {
+// ObjectName gbeanName = (ObjectName) iterator.next();
+// if (State.RUNNING_INDEX != kernel.getGBeanState(gbeanName)) {
+// throw new InvalidConfigurationException("Configuration " + getConfigurationId(configuration) + " failed to start because gbean " + gbeanName + " did not start");
+// }
+// }
} catch (GBeanNotFoundException e) {
throw new InvalidConfigException(e);
}
// todo clean up after failure
if (configurationList != null) {
- configurationList.addConfiguration(configuration.getId().toString());
+ configurationList.addConfiguration(getConfigurationId(configuration).toString());
}
}
- public void stopConfiguration(Artifact configId) throws InvalidConfigException {
- Configuration configuration = getConfiguration(configId);
+ public void stopConfiguration(Configuration configuration) throws InvalidConfigException {
+ stopConfiguration(getConfigurationId(configuration));
+ }
- stopConfiguration(configuration);
+ public void stopConfiguration(Artifact id) throws InvalidConfigException {
+ ConfigurationStatus configurationStatus = (ConfigurationStatus) configurations.get(id);
+ if (configurationStatus == null) {
+ throw new InvalidConfigurationException("Configuration is not loaded " + id);
+ }
+
+ List stopList = configurationStatus.stop();
+ for (Iterator iterator = stopList.iterator(); iterator.hasNext();) {
+ Configuration configuration = (Configuration) iterator.next();
+ stop(configuration);
+ }
}
- public void stopConfiguration(Configuration configuration) throws InvalidConfigException {
+ private void stop(Configuration configuration) throws InvalidConfigException {
try {
Collection gbeans = configuration.getGBeans().keySet();
// stop the gbeans
for (Iterator iterator = gbeans.iterator(); iterator.hasNext();) {
+ // todo should try to stop all beans
ObjectName gbeanName = (ObjectName) iterator.next();
kernel.stopGBean(gbeanName);
}
@@ -418,18 +495,33 @@
throw new InvalidConfigException("Could not stop gbeans in configuration", e);
}
if (configurationList != null) {
- configurationList.removeConfiguration(configuration.getId().toString());
+ configurationList.removeConfiguration(getConfigurationId(configuration).toString());
}
}
public void unloadConfiguration(Configuration configuration) throws NoSuchConfigException {
- unloadConfiguration(configuration.getId());
+ unloadConfiguration(getConfigurationId(configuration));
+ }
+
+ private Artifact getConfigurationId(Configuration configuration) {
+ return configuration.getEnvironment().getConfigId();
+ }
+
+ public void unloadConfiguration(Artifact id) throws NoSuchConfigException {
+ ConfigurationStatus configurationStatus = (ConfigurationStatus) configurations.get(id);
+ List unloadList = configurationStatus.unload();
+ for (Iterator iterator = unloadList.iterator(); iterator.hasNext();) {
+ Configuration configuration = (Configuration) iterator.next();
+ Artifact configurationId = getConfigurationId(configuration);
+ unload(configurationId);
+ configurations.remove(configurationId);
+ }
}
- public void unloadConfiguration(Artifact configId) throws NoSuchConfigException {
+ private void unload(Artifact configurationId) throws NoSuchConfigException {
ObjectName configName;
try {
- configName = Configuration.getConfigurationObjectName(configId);
+ configName = Configuration.getConfigurationObjectName(configurationId);
} catch (InvalidConfigException e) {
throw new NoSuchConfigException("Could not construct configuration object name", e);
}
@@ -526,6 +618,78 @@
}
}
}
+ }
+ }
+
+ private static class ConfigurationStatus {
+ private final Configuration configuration;
+ private final List parents;
+ private int loadCount = 0;
+ private int startCount = 0;
+
+ public ConfigurationStatus(Configuration configuration, List parents) {
+ this.configuration = configuration;
+ this.parents = parents;
+ }
+
+ public Configuration getConfiguration() {
+ return configuration;
+ }
+
+ public int getLoadCount() {
+ return loadCount;
+ }
+
+ public void load() {
+ for (Iterator iterator = parents.iterator(); iterator.hasNext();) {
+ ConfigurationStatus parent = (ConfigurationStatus) iterator.next();
+ parent.load();
+ }
+ loadCount++;
+ }
+
+ public List unload() {
+ List unloadList = new LinkedList();
+ for (Iterator iterator = parents.iterator(); iterator.hasNext();) {
+ ConfigurationStatus parent = (ConfigurationStatus) iterator.next();
+ unloadList.addAll(parent.unload());
+ }
+ loadCount--;
+ if (loadCount == 0) {
+ assert(startCount == 0);
+ unloadList.add(configuration);
+ }
+ return unloadList;
+ }
+
+ public int getStartCount() {
+ return startCount;
+ }
+
+ public List start() {
+ List startList = new LinkedList();
+ for (Iterator iterator = parents.iterator(); iterator.hasNext();) {
+ ConfigurationStatus parent = (ConfigurationStatus) iterator.next();
+ startList.addAll(parent.start());
+ }
+ startCount++;
+ if (startCount == 1) {
+ startList.add(configuration);
+ }
+ return startList;
+ }
+
+ public List stop() {
+ List stopList = new LinkedList();
+ for (Iterator iterator = parents.iterator(); iterator.hasNext();) {
+ ConfigurationStatus parent = (ConfigurationStatus) iterator.next();
+ stopList.addAll(parent.stop());
+ }
+ startCount--;
+ if (startCount == 0) {
+ stopList.add(configuration);
+ }
+ return stopList;
}
}
}
Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationUtil.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationUtil.java?rev=383519&r1=383518&r2=383519&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationUtil.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationUtil.java Mon Mar 6 03:35:35 2006
@@ -85,6 +85,8 @@
}
}
+ ConfigurationManager configurationManager = getConfigurationManager(kernel);
+ configurationManager.loadConfiguration(configId);
return configurationName;
}
Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/log/GeronimoLogging.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/log/GeronimoLogging.java?rev=383519&r1=383518&r2=383519&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/log/GeronimoLogging.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/log/GeronimoLogging.java Mon Mar 6 03:35:35 2006
@@ -33,7 +33,7 @@
public static final GeronimoLogging FATAL = new GeronimoLogging("FATAL");
private static boolean initialized = false;
- private static GeronimoLogging consoleLogLevel;
+ private static GeronimoLogging consoleLogLevel = ERROR;
private static GeronimoLogging defaultLevel;
/**
Modified: geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/config/ConfigurationManagerTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/config/ConfigurationManagerTest.java?rev=383519&r1=383518&r2=383519&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/config/ConfigurationManagerTest.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/config/ConfigurationManagerTest.java Mon Mar 6 03:35:35 2006
@@ -53,13 +53,14 @@
private Artifact artifact2;
private Artifact artifact3;
private Map configurations = new HashMap();
- private ConfigurationManagerImpl configurationManager;
+ private ConfigurationManager configurationManager;
public void test() throws Exception {
- List list = configurationManager.loadConfiguration(artifact3);
- assertTrue(list.contains(artifact3));
- assertTrue(list.contains(artifact2));
- assertTrue(list.contains(artifact1));
+ Configuration configuration = configurationManager.loadConfiguration(artifact3);
+ assertEquals(artifact3, configuration.getId());
+ assertTrue(configurationManager.isLoaded(artifact3));
+ assertTrue(configurationManager.isLoaded(artifact2));
+ assertTrue(configurationManager.isLoaded(artifact1));
assertTrue(kernel.isLoaded(Configuration.getConfigurationObjectName(artifact3))) ;
assertTrue(kernel.isLoaded(Configuration.getConfigurationObjectName(artifact2))) ;
assertTrue(kernel.isLoaded(Configuration.getConfigurationObjectName(artifact1))) ;
Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationDump.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationDump.java?rev=383519&r1=383518&r2=383519&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationDump.java (original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationDump.java Mon Mar 6 03:35:35 2006
@@ -264,8 +264,8 @@
loadRecursive(kernel, configurationStore, configID, ancestors, preloaded);
for (Iterator iterator = ancestors.iterator(); iterator.hasNext();) {
- URI name = (URI) iterator.next();
- ObjectName configName = Configuration.getConfigurationObjectName(name);
+ Artifact id = (Artifact) iterator.next();
+ ObjectName configName = Configuration.getConfigurationObjectName(id);
kernel.startGBean(configName);
}
}
Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/logging/log4j/Log4jService.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/logging/log4j/Log4jService.java?rev=383519&r1=383518&r2=383519&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/logging/log4j/Log4jService.java (original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/logging/log4j/Log4jService.java Mon Mar 6 03:35:35 2006
@@ -507,7 +507,7 @@
*/
public void reconfigure() {
File file = resolveConfigurationFile();
- if (file == null) {
+ if (file == null || file.exists()) {
return;
}
Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/CommandLine.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/CommandLine.java?rev=383519&r1=383518&r2=383519&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/CommandLine.java (original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/CommandLine.java Mon Mar 6 03:35:35 2006
@@ -110,11 +110,8 @@
try {
for (Iterator i = configurations.iterator(); i.hasNext();) {
Artifact configID = (Artifact) i.next();
- List list = configurationManager.loadConfiguration(configID);
- for (Iterator iterator = list.iterator(); iterator.hasNext();) {
- Artifact name = (Artifact) iterator.next();
- configurationManager.startConfiguration(name);
- }
+ configurationManager.loadConfiguration(configID);
+ configurationManager.startConfiguration(configID);
}
} finally {
ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager);
Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java?rev=383519&r1=383518&r2=383519&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java (original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java Mon Mar 6 03:35:35 2006
@@ -296,13 +296,10 @@
for (Iterator i = configs.iterator(); i.hasNext();) {
Artifact configID = (Artifact) i.next();
monitor.configurationLoading(configID);
- List list = configurationManager.loadConfiguration(configID);
+ configurationManager.loadConfiguration(configID);
monitor.configurationLoaded(configID);
monitor.configurationStarting(configID);
- for (Iterator iterator = list.iterator(); iterator.hasNext();) {
- Artifact name = (Artifact) iterator.next();
- configurationManager.startConfiguration(name);
- }
+ configurationManager.startConfiguration(configID);
monitor.configurationStarted(configID);
}
} finally {
Modified: geronimo/branches/1.1/modules/tomcat-builder/src/test/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilderTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/tomcat-builder/src/test/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilderTest.java?rev=383519&r1=383518&r2=383519&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/tomcat-builder/src/test/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilderTest.java (original)
+++ geronimo/branches/1.1/modules/tomcat-builder/src/test/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilderTest.java Mon Mar 6 03:35:35 2006
@@ -217,6 +217,7 @@
//what is this testing?
configuration = configurationManager.loadConfiguration(earContext.getConfigurationData(), configurationStore);
+ configurationManager.startConfiguration(configuration);
configurationManager.stopConfiguration(configuration);
configurationManager.unloadConfiguration(configuration);
}
Modified: geronimo/branches/1.1/plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/StartServer.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/StartServer.java?rev=383519&r1=383518&r2=383519&view=diff
==============================================================================
--- geronimo/branches/1.1/plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/StartServer.java (original)
+++ geronimo/branches/1.1/plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/StartServer.java Mon Mar 6 03:35:35 2006
@@ -105,12 +105,9 @@
try {
for (Iterator i = configList.iterator(); i.hasNext();) {
Artifact configID = (Artifact) i.next();
- List list = configurationManager.loadConfiguration(configID);
- for (Iterator iterator = list.iterator(); iterator.hasNext();) {
- Artifact name = (Artifact) iterator.next();
- configurationManager.startConfiguration(name);
- System.out.println("started gbean: " + name);
- }
+ configurationManager.loadConfiguration(configID);
+ configurationManager.startConfiguration(configID);
+ System.out.println("started gbean: " + configID);
}
} finally {
ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager);
|