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/02 18:00:56 UTC
svn commit: r1308408 - in
/geronimo/server/branches/3.0-beta/framework/modules:
geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java
geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java
Author: xuhaihong
Date: Mon Apr 2 16:00:55 2012
New Revision: 1308408
URL: http://svn.apache.org/viewvc?rev=1308408&view=rev
Log:
GERONIMO-6112 Move the validation codes earlier, and avoid some unneeded process
Modified:
geronimo/server/branches/3.0-beta/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java
geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java
Modified: geronimo/server/branches/3.0-beta/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-beta/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java?rev=1308408&r1=1308407&r2=1308408&view=diff
==============================================================================
--- geronimo/server/branches/3.0-beta/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java (original)
+++ geronimo/server/branches/3.0-beta/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java Mon Apr 2 16:00:55 2012
@@ -53,13 +53,13 @@ import org.apache.geronimo.kernel.config
import org.apache.geronimo.kernel.config.ConfigurationUtil;
import org.apache.geronimo.kernel.config.DeploymentWatcher;
import org.apache.geronimo.kernel.config.InvalidConfigException;
-import org.apache.xbean.osgi.bundle.util.BundleClassLoader;
import org.apache.geronimo.kernel.repository.Artifact;
import org.apache.geronimo.kernel.repository.ArtifactResolver;
import org.apache.geronimo.kernel.util.FileUtils;
import org.apache.geronimo.kernel.util.JarUtils;
import org.apache.geronimo.system.configuration.ExecutableConfigurationUtil;
import org.apache.geronimo.system.main.CommandLineManifest;
+import org.apache.xbean.osgi.bundle.util.BundleClassLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -76,14 +76,14 @@ public class Deployer implements GBeanLi
private final boolean CLEAN_UP_ON_START = System.getProperty(CLEAN_UP_ON_START_KEY) == null ? true : Boolean.getBoolean(CLEAN_UP_ON_START_KEY);
private DeployerReaper reaper;
private final String remoteDeployAddress;
- private final Collection builders;
- private final Collection stores;
- private final Collection watchers;
+ private final Collection<ConfigurationBuilder> builders;
+ private final Collection<ConfigurationStore> stores;
+ private final Collection<DeploymentWatcher> watchers;
private final ArtifactResolver artifactResolver;
private final Kernel kernel;
private static final URI PLAN_LOCATION = URI.create("META-INF/plan.xml");
- public Deployer(String remoteDeployAddress, Collection builders, Collection stores, Collection watchers, Kernel kernel) throws GBeanNotFoundException {
+ public Deployer(String remoteDeployAddress, Collection<ConfigurationBuilder> builders, Collection<ConfigurationStore> stores, Collection<DeploymentWatcher> watchers, Kernel kernel) throws GBeanNotFoundException {
this(remoteDeployAddress, builders, stores, watchers, getArtifactResolver(kernel), kernel);
}
@@ -92,7 +92,7 @@ public class Deployer implements GBeanLi
return configurationManager.getArtifactResolver();
}
- public Deployer(String remoteDeployAddress, Collection builders, Collection stores, Collection watchers, ArtifactResolver artifactResolver, Kernel kernel) {
+ public Deployer(String remoteDeployAddress, Collection<ConfigurationBuilder> builders, Collection<ConfigurationStore> stores, Collection<DeploymentWatcher> watchers, ArtifactResolver artifactResolver, Kernel kernel) {
this.remoteDeployAddress = remoteDeployAddress;
this.builders = builders;
this.stores = stores;
@@ -105,11 +105,11 @@ public class Deployer implements GBeanLi
}
- public List deploy(boolean inPlace, File moduleFile, File planFile) throws DeploymentException {
+ public List<String> deploy(boolean inPlace, File moduleFile, File planFile) throws DeploymentException {
return deploy(inPlace, moduleFile, planFile, null);
}
- public List deploy(boolean inPlace, File moduleFile, File planFile, String targetConfigStore) throws DeploymentException {
+ public List<String> deploy(boolean inPlace, File moduleFile, File planFile, String targetConfigStore) throws DeploymentException {
File originalModuleFile = moduleFile;
File tmpDir = null;
if (moduleFile != null && !moduleFile.isDirectory()) {
@@ -162,16 +162,14 @@ public class Deployer implements GBeanLi
*/
public String getRemoteDeployUploadURL() {
// Get the token GBean from the remote deployment configuration
- Set set = kernel.listGBeans(new AbstractNameQuery("org.apache.geronimo.deployment.remote.RemoteDeployToken"));
+ Set<AbstractName> set = kernel.listGBeans(new AbstractNameQuery("org.apache.geronimo.deployment.remote.RemoteDeployToken"));
if (set.size() == 0) {
return null;
}
- AbstractName token = (AbstractName) set.iterator().next();
+ AbstractName token = set.iterator().next();
// Identify the parent configuration for that GBean
- set = kernel.getDependencyManager().getParents(token);
ObjectName config = null;
- for (Iterator it = set.iterator(); it.hasNext();) {
- AbstractName name = (AbstractName) it.next();
+ for (AbstractName name : kernel.getDependencyManager().getParents(token)) {
if (Configuration.isConfigurationObjectName(name.getObjectName())) {
config = name.getObjectName();
break;
@@ -205,7 +203,7 @@ public class Deployer implements GBeanLi
}
}
- public List deploy(boolean inPlace,
+ public List<String> deploy(boolean inPlace,
File moduleFile,
File planFile,
File targetFile,
@@ -220,19 +218,22 @@ public class Deployer implements GBeanLi
} else if (stores.isEmpty()) {
throw new DeploymentException("No ConfigurationStores!");
}
- validatePlanFile(planFile);
-
- JarFile module = getModule(inPlace, moduleFile);
+ validatePlanFile(planFile);
ModuleIDBuilder idBuilder = new ModuleIDBuilder();
DeploymentContext context = null;
+ JarFile module = null;
try {
+ module = getModule(inPlace, moduleFile);
+
+ validateModuleFile(module);
+
FileUtils.beginRecordTempFiles();
Object plan = null;
ConfigurationBuilder builder = null;
- for (Iterator i = builders.iterator(); i.hasNext();) {
- ConfigurationBuilder candidate = (ConfigurationBuilder) i.next();
+ for (Iterator<ConfigurationBuilder> i = builders.iterator(); i.hasNext();) {
+ ConfigurationBuilder candidate = i.next();
plan = candidate.getDeploymentPlan(planFile, module, idBuilder);
if (plan != null) {
builder = candidate;
@@ -254,7 +255,6 @@ public class Deployer implements GBeanLi
// It's our responsibility to close this context, once we're done with it...
context = builder.buildConfiguration(inPlace, configID, plan, module, stores, artifactResolver, store);
- isNotCar(context.getBaseDir());
// Copy the external plan to the META-INF folder with the uniform name plan.xml if there is nothing there already
if (planFile != null && !context.getTargetFile(PLAN_LOCATION).exists()) {
context.addFile(PLAN_LOCATION, planFile);
@@ -296,17 +296,9 @@ public class Deployer implements GBeanLi
}
}
- private void isNotCar(File module) throws DeploymentException {
- File meta = new File(module, "META-INF");
- if (meta.exists()) {
- File checkSum = new File(meta, "config.ser");
- if (checkSum.exists()) {
- throw new DeploymentException("Have found the config.ser in the deploy package." +
- " It should be a car. Please use the install-plugin command to install it.");
- }
- }
- else {
- return;
+ private void validateModuleFile(JarFile module) throws DeploymentException {
+ if (module != null && module.getEntry("META-INF/config.ser") != null) {
+ throw new DeploymentException("The target applicaiton is an Geronimo plugin as config.ser was found in the META-INF directory, please use the install-plugin command.");
}
}
@@ -316,7 +308,7 @@ public class Deployer implements GBeanLi
AbstractName targetStoreName = new AbstractName(new URI(targetConfigurationStore));
return (ConfigurationStore) kernel.getGBean(targetStoreName);
} else {
- return (ConfigurationStore) stores.iterator().next();
+ return stores.iterator().next();
}
}
@@ -451,7 +443,6 @@ public class Deployer implements GBeanLi
}
private JarFile getModule(boolean inPlace, File moduleFile) throws DeploymentException {
- JarFile module = null;
if (moduleFile != null) {
if (inPlace && !moduleFile.isDirectory()) {
throw new DeploymentException("In place deployment is not allowed for packed module");
@@ -460,12 +451,12 @@ public class Deployer implements GBeanLi
throw new DeploymentException("Module file does not exist: " + moduleFile.getAbsolutePath());
}
try {
- module = JarUtils.createJarFile(moduleFile);
+ return JarUtils.createJarFile(moduleFile);
} catch (IOException e) {
throw new DeploymentException("Cound not open module file: " + moduleFile.getAbsolutePath(), e);
}
}
- return module;
+ return null;
}
private void validatePlanFile(File planFile) throws DeploymentException {
@@ -485,14 +476,14 @@ public class Deployer implements GBeanLi
}
}
- private void notifyWatchers(List list) {
+ private void notifyWatchers(List<String> list) {
Artifact[] arts = new Artifact[list.size()];
for (int i = 0; i < list.size(); i++) {
- String s = (String) list.get(i);
+ String s = list.get(i);
arts[i] = Artifact.create(s);
}
- for (Iterator it = watchers.iterator(); it.hasNext();) {
- DeploymentWatcher watcher = (DeploymentWatcher) it.next();
+ for (Iterator<DeploymentWatcher> it = watchers.iterator(); it.hasNext();) {
+ DeploymentWatcher watcher = it.next();
for (int i = 0; i < arts.length; i++) {
Artifact art = arts[i];
watcher.deployed(art);
@@ -625,7 +616,7 @@ public class Deployer implements GBeanLi
if (pendingDeletionIndex.size() == 0)
return;
// Otherwise, attempt to delete all of the directories
- Enumeration list = pendingDeletionIndex.propertyNames();
+ Enumeration<?> list = pendingDeletionIndex.propertyNames();
while (list.hasMoreElements()) {
String dirName = (String) list.nextElement();
File deleteDir = new File(dirName);
Modified: geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java?rev=1308408&r1=1308407&r2=1308408&view=diff
==============================================================================
--- geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java (original)
+++ geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java Mon Apr 2 16:00:55 2012
@@ -17,14 +17,6 @@
package org.apache.geronimo.kernel.basic;
-import org.apache.geronimo.gbean.AbstractName;
-import org.apache.geronimo.gbean.AbstractNameQuery;
-import org.apache.geronimo.kernel.DependencyManager;
-import org.apache.geronimo.kernel.lifecycle.LifecycleAdapter;
-import org.apache.geronimo.kernel.lifecycle.LifecycleListener;
-import org.apache.geronimo.kernel.lifecycle.LifecycleMonitor;
-
-import javax.management.ObjectName;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -32,6 +24,13 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.kernel.DependencyManager;
+import org.apache.geronimo.kernel.lifecycle.LifecycleAdapter;
+import org.apache.geronimo.kernel.lifecycle.LifecycleListener;
+import org.apache.geronimo.kernel.lifecycle.LifecycleMonitor;
+
/**
* DependencyManager is the record keeper of the dependencies in Geronimo. The DependencyManager
* does not enforce any dependencies, it is simply a place where components can register their intent
@@ -59,12 +58,12 @@ public class BasicDependencyManager impl
/**
* A map from child names to a list of parents.
*/
- private final Map childToParentMap = new HashMap();
+ private final Map<AbstractName, Set<AbstractName>> childToParentMap = new HashMap<AbstractName, Set<AbstractName>>();
/**
* A map from parent back to a list of its children.
*/
- private final Map parentToChildMap = new HashMap();
+ private final Map<AbstractName, Set<AbstractName>> parentToChildMap = new HashMap<AbstractName, Set<AbstractName>>();
public BasicDependencyManager(LifecycleMonitor lifecycleMonitor) throws Exception {
assert lifecycleMonitor != null;
@@ -85,16 +84,16 @@ public class BasicDependencyManager impl
* @param parent the component the child is depending on
*/
public synchronized void addDependency(AbstractName child, AbstractName parent) {
- Set parents = (Set) childToParentMap.get(child);
+ Set<AbstractName> parents = childToParentMap.get(child);
if (parents == null) {
- parents = new HashSet();
+ parents = new HashSet<AbstractName>();
childToParentMap.put(child, parents);
}
parents.add(parent);
- Set children = (Set) parentToChildMap.get(parent);
+ Set<AbstractName> children = parentToChildMap.get(parent);
if (children == null) {
- children = new HashSet();
+ children = new HashSet<AbstractName>();
parentToChildMap.put(parent, children);
}
children.add(child);
@@ -107,12 +106,12 @@ public class BasicDependencyManager impl
* @param parent the component that the child wil no longer depend on
*/
public synchronized void removeDependency(AbstractName child, AbstractName parent) {
- Set parents = (Set) childToParentMap.get(child);
+ Set<AbstractName> parents = childToParentMap.get(child);
if (parents != null) {
parents.remove(parent);
}
- Set children = (Set) parentToChildMap.get(parent);
+ Set<AbstractName> children = parentToChildMap.get(parent);
if (children != null) {
children.remove(child);
}
@@ -124,17 +123,16 @@ public class BasicDependencyManager impl
* @param child the component that will no longer depend on anything
*/
public synchronized void removeAllDependencies(AbstractName child) {
- Set parents = (Set) childToParentMap.remove(child);
+ Set<AbstractName> parents = childToParentMap.remove(child);
if (parents == null) {
return;
}
- for (Iterator iterator = parents.iterator(); iterator.hasNext();) {
- ObjectName parent = (ObjectName) iterator.next();
- Set children = (Set) parentToChildMap.get(parent);
+ for (Iterator<AbstractName> iterator = parents.iterator(); iterator.hasNext();) {
+ AbstractName parent = iterator.next();
+ Set<AbstractName> children = parentToChildMap.get(parent);
if (children != null) {
children.remove(child);
}
-
}
}
@@ -144,20 +142,20 @@ public class BasicDependencyManager impl
* @param child the dependent component
* @param parents the set of components the child is depending on
*/
- public synchronized void addDependencies(AbstractName child, Set parents) {
- Set existingParents = (Set) childToParentMap.get(child);
+ public synchronized void addDependencies(AbstractName child, Set<AbstractName> parents) {
+ Set<AbstractName> existingParents = childToParentMap.get(child);
if (existingParents == null) {
- existingParents = new HashSet(parents);
+ existingParents = new HashSet<AbstractName>(parents);
childToParentMap.put(child, existingParents);
} else {
existingParents.addAll(parents);
}
- for (Iterator i = parents.iterator(); i.hasNext();) {
- Object startParent = i.next();
- Set children = (Set) parentToChildMap.get(startParent);
+ for (Iterator<AbstractName> i = parents.iterator(); i.hasNext();) {
+ AbstractName startParent = i.next();
+ Set<AbstractName> children = parentToChildMap.get(startParent);
if (children == null) {
- children = new HashSet();
+ children = new HashSet<AbstractName>();
parentToChildMap.put(startParent, children);
}
children.add(child);
@@ -170,12 +168,12 @@ public class BasicDependencyManager impl
* @param child the dependent component
* @return a collection containing all of the components the child depends on; will never be null
*/
- public synchronized Set getParents(AbstractName child) {
- Set parents = (Set) childToParentMap.get(child);
+ public synchronized Set<AbstractName> getParents(AbstractName child) {
+ Set<AbstractName> parents = childToParentMap.get(child);
if (parents == null) {
- return Collections.EMPTY_SET;
+ return Collections.<AbstractName>emptySet();
}
- return new HashSet(parents);
+ return new HashSet<AbstractName>(parents);
}
/**
@@ -184,12 +182,12 @@ public class BasicDependencyManager impl
* @param parent the component the returned childen set depend on
* @return a collection containing all of the components that depend on the parent; will never be null
*/
- public synchronized Set getChildren(AbstractName parent) {
- Set children = (Set) parentToChildMap.get(parent);
+ public synchronized Set<AbstractName> getChildren(AbstractName parent) {
+ Set<AbstractName> children = parentToChildMap.get(parent);
if (children == null) {
- return Collections.EMPTY_SET;
+ return Collections.<AbstractName>emptySet();
}
- return new HashSet(children);
+ return new HashSet<AbstractName>(children);
}