Skip to content

Commit

Permalink
GERONIMO-6112 Move the validation codes earlier, and avoid some unnee…
Browse files Browse the repository at this point in the history
…ded process

git-svn-id: https://svn.apache.org/repos/asf/geronimo/server/trunk@1308424 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Haihong Xu committed Apr 2, 2012
1 parent 3d760ad commit d95990c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 50 deletions.
Expand Up @@ -77,7 +77,7 @@ public class DeployerImpl implements Deployer {
private static final String REMOTE_DEPLOY_ADDRESS = "remoteDeployAddress";

private String remoteDeployAddress;

@Reference(cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, referenceInterface = ConfigurationBuilder.class, policy = ReferencePolicy.DYNAMIC)
private final Collection<ConfigurationBuilder> configurationBuilders = new ArrayList<ConfigurationBuilder>();

Expand Down Expand Up @@ -133,27 +133,27 @@ public void doStop() throws Exception {
public void bindConfigurationStore(ConfigurationStore store) {
configurationStores.add(store);
}

public void unbindConfigurationStore(ConfigurationStore store) {
configurationStores.remove(store);
}

public void bindConfigurationBuilder(ConfigurationBuilder builder) {
configurationBuilders.add(builder);
}

public void unbindConfigurationBuilder(ConfigurationBuilder builder) {
configurationBuilders.remove(builder);
}

public void bindDeploymentWatcher(DeploymentWatcher watcher) {
deploymentWatchers.add(watcher);
}

public void unbindDeploymentWatcher(DeploymentWatcher watcher) {
deploymentWatchers.remove(watcher);
}

public void setArtifactResolver(ArtifactResolver artifactResolver) {
this.artifactResolver = artifactResolver;
}
Expand Down Expand Up @@ -290,16 +290,18 @@ public List<String> deploy(boolean inPlace,
}
validatePlanFile(planFile);

JarFile module = getModule(inPlace, moduleFile);

ModuleIDBuilder idBuilder = new ModuleIDBuilder();

DeploymentContext context = null;
JarFile module = null;
try {
module = getModule(inPlace, moduleFile);
validateModuleFile(module);

Object plan = null;
ConfigurationBuilder builder = null;
for (Iterator i = configurationBuilders.iterator(); i.hasNext();) {
ConfigurationBuilder candidate = (ConfigurationBuilder) i.next();
for (Iterator<ConfigurationBuilder> i = configurationBuilders.iterator(); i.hasNext();) {
ConfigurationBuilder candidate = i.next();
plan = candidate.getDeploymentPlan(planFile, module, idBuilder);
if (plan != null) {
builder = candidate;
Expand Down Expand Up @@ -369,6 +371,12 @@ public List<String> deploy(boolean inPlace,
}
}

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.");
}
}

private ConfigurationStore getConfigurationStore(String targetConfigurationStore)
throws URISyntaxException, GBeanNotFoundException {
// if (targetConfigurationStore != null) {
Expand Down Expand Up @@ -559,24 +567,24 @@ private void validatePlanFile(File planFile) throws DeploymentException {
}
}

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 = deploymentWatchers.iterator(); it.hasNext();) {
DeploymentWatcher watcher = (DeploymentWatcher) it.next();
for (Iterator<DeploymentWatcher> it = deploymentWatchers.iterator(); it.hasNext();) {
DeploymentWatcher watcher = it.next();
for (int i = 0; i < arts.length; i++) {
Artifact art = arts[i];
watcher.deployed(art);
}
}
}

private void cleanupConfigurations(List configurations) {
for (Iterator iterator = configurations.iterator(); iterator.hasNext();) {
ConfigurationData configurationData = (ConfigurationData) iterator.next();
private void cleanupConfigurations(List<ConfigurationData> configurations) {
for (Iterator<ConfigurationData> iterator = configurations.iterator(); iterator.hasNext();) {
ConfigurationData configurationData = iterator.next();
File configurationDir = configurationData.getConfigurationDir();
if (!FileUtils.recursiveDelete(configurationDir)) {
reaper.delete(configurationDir.getAbsolutePath(), "delete");
Expand Down Expand Up @@ -664,7 +672,7 @@ public void reap() {
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);
Expand Down
Expand Up @@ -66,22 +66,22 @@ public interface DependencyManager {
* @param child the dependent component
* @param parents the set of components the child is depending on
*/
public void addDependencies(AbstractName child, Set parents);
public void addDependencies(AbstractName child, Set<AbstractName> parents);

/**
* Gets the set of parents that the child is depending on
*
* @param child the dependent component
* @return a collection containing all of the components the child depends on; will never be null
*/
public Set getParents(AbstractName child);
public Set<AbstractName> getParents(AbstractName child);

/**
* Gets all of the MBeans that have a dependency on the specified startParent.
*
* @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 Set getChildren(AbstractName parent);
public Set<AbstractName> getChildren(AbstractName parent);

}
Expand Up @@ -24,7 +24,6 @@
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;
Expand Down Expand Up @@ -59,12 +58,12 @@ public class BasicDependencyManager implements DependencyManager {
/**
* 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) {
assert lifecycleMonitor != null;
Expand All @@ -85,16 +84,16 @@ public synchronized void close() {
* @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);
Expand All @@ -107,12 +106,12 @@ public synchronized void addDependency(AbstractName child, AbstractName parent)
* @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);
}
Expand All @@ -124,13 +123,13 @@ public synchronized void removeDependency(AbstractName child, AbstractName paren
* @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);
}
Expand All @@ -144,20 +143,20 @@ public synchronized void removeAllDependencies(AbstractName child) {
* @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);
Expand All @@ -170,12 +169,12 @@ public synchronized void addDependencies(AbstractName child, Set parents) {
* @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);
}

/**
Expand All @@ -184,12 +183,12 @@ public synchronized Set getParents(AbstractName child) {
* @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);
}


Expand Down

0 comments on commit d95990c

Please sign in to comment.