From cfa2416a6c75e850285f2d82427cb2eeb3f669e4 Mon Sep 17 00:00:00 2001 From: antelder Date: Fri, 4 Mar 2011 13:08:02 +0000 Subject: Update to use a map instead of a list to store the start composites to make the lookup easier git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1077928 13f79535-47bb-0310-9956-ffa450edef68 --- .../tuscany/sca/impl/InstalledContribution.java | 23 ++++++++++------------ .../java/org/apache/tuscany/sca/impl/NodeImpl.java | 11 +++-------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/InstalledContribution.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/InstalledContribution.java index 750a13f81a..d3a2526ab9 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/InstalledContribution.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/InstalledContribution.java @@ -34,7 +34,7 @@ public class InstalledContribution { private String url; private Contribution contribution; private List defaultDeployables = new ArrayList(); - private List startededComposites = new ArrayList(); + private Map startedComposites = new HashMap(); private Map stoppedComposites = new HashMap(); private List dependentContributionURIs; @@ -60,33 +60,30 @@ public class InstalledContribution { public List getDefaultDeployables() { return defaultDeployables; } - public List getDeployedComposites() { - return startededComposites; + public List getStartedCompositeURIs() { + return new ArrayList(startedComposites.keySet()); } public List getDependentContributionURIs() { return dependentContributionURIs; } public void stop(String compositeURI) throws ActivationException { - for (DeployedComposite dc : getDeployedComposites()) { - if (compositeURI.equals(dc.getURI())) { - getDeployedComposites().remove(dc); - dc.stop(); - stoppedComposites.put(compositeURI, dc); - return; - } + DeployedComposite dc = startedComposites.remove(compositeURI); + if (dc == null) { + throw new IllegalStateException("composite not deployed: " + compositeURI); } - throw new IllegalStateException("composite not deployed: " + compositeURI); + dc.stop(); + stoppedComposites.put(compositeURI, dc); } public void start(DeployedComposite composite) { - startededComposites.add(composite); + startedComposites.put(composite.getURI(), composite); } public boolean restart(String compositeURI) throws ActivationException { DeployedComposite dc = stoppedComposites.remove(compositeURI); if (dc != null) { dc.start(); - startededComposites.add(dc); + startedComposites.put(dc.getURI(), dc); } return dc != null; } diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java index 2e0c4fea02..19e05f9408 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java @@ -232,10 +232,9 @@ public class NodeImpl implements Node { removedContributionURIs.addAll(removeContribution(dependent)); } installedContributions.remove(contributionURI); - for (DeployedComposite dc : ic.getDeployedComposites()) { - dc.stop(); + for (String compositeURI : ic.getStartedCompositeURIs()) { + ic.stop(compositeURI); } - ic.getDeployedComposites().clear(); } return removedContributionURIs; } @@ -404,15 +403,11 @@ public class NodeImpl implements Node { } public List getStartedCompositeURIs(String contributionURI) { - ArrayList compositeURIs = new ArrayList(); InstalledContribution ic = installedContributions.get(contributionURI); if (ic == null) { throw new IllegalArgumentException("no contribution found for: " + contributionURI); } - for (DeployedComposite dc : ic.getDeployedComposites()) { - compositeURIs.add(dc.getURI()); - } - return compositeURIs; + return ic.getStartedCompositeURIs(); } public List getInstalledContributionURIs() { -- cgit v1.2.3