summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2011-05-17 11:09:38 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2011-05-17 11:09:38 +0000
commit8435e4751b9caa6c3cc2d9c60e3fca5becf8b5bf (patch)
treedb299833adf3b5a84117f675d43ea63116429c91 /sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java
parent9365ad87df669a52da9f72adaab101071dec5be2 (diff)
Merege the refactoring in nodeImpl2 back into NodeImpl
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1104140 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java')
-rw-r--r--sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/impl/NodeImpl.java648
1 files changed, 236 insertions, 412 deletions
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 a8b7cac8f3..bc5a1961ec 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
@@ -19,63 +19,41 @@
package org.apache.tuscany.sca.impl;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
import java.io.Reader;
+import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import javax.xml.namespace.QName;
-import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
import org.apache.tuscany.sca.Node;
import org.apache.tuscany.sca.TuscanyRuntime;
import org.apache.tuscany.sca.assembly.AssemblyFactory;
import org.apache.tuscany.sca.assembly.Base;
-import org.apache.tuscany.sca.assembly.Component;
-import org.apache.tuscany.sca.assembly.ComponentReference;
-import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.Composite;
-import org.apache.tuscany.sca.assembly.Endpoint;
-import org.apache.tuscany.sca.assembly.EndpointReference;
-import org.apache.tuscany.sca.assembly.Multiplicity;
-import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.xml.Utils;
import org.apache.tuscany.sca.common.java.io.IOHelper;
-import org.apache.tuscany.sca.context.CompositeContext;
-import org.apache.tuscany.sca.contribution.Artifact;
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.contribution.ContributionMetadata;
+import org.apache.tuscany.sca.contribution.Import;
+import org.apache.tuscany.sca.contribution.java.JavaImport;
+import org.apache.tuscany.sca.contribution.namespace.NamespaceImport;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
-import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
-import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory;
-import org.apache.tuscany.sca.core.invocation.ProxyFactory;
-import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint;
import org.apache.tuscany.sca.deployment.Deployer;
-import org.apache.tuscany.sca.interfacedef.Interface;
-import org.apache.tuscany.sca.interfacedef.InterfaceContract;
-import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
-import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
-import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.ValidationException;
import org.apache.tuscany.sca.runtime.ActivationException;
import org.apache.tuscany.sca.runtime.CompositeActivator;
+import org.apache.tuscany.sca.runtime.ContributionListener;
import org.apache.tuscany.sca.runtime.DomainRegistry;
-import org.apache.tuscany.sca.runtime.RuntimeComponent;
-import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
-import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+import org.apache.tuscany.sca.runtime.InstalledContribution;
import org.oasisopen.sca.NoSuchServiceException;
-import org.oasisopen.sca.ServiceRuntimeException;
public class NodeImpl implements Node {
@@ -85,179 +63,204 @@ public class NodeImpl implements Node {
private DomainRegistry domainRegistry;
private ExtensionPointRegistry extensionPointRegistry;
private TuscanyRuntime tuscanyRuntime;
- private Map<String, InstalledContribution> locallyInstalledContributions = new HashMap<String, InstalledContribution>();
- public NodeImpl(String domainName, Deployer deployer, CompositeActivator compositeActivator, DomainRegistry domainRegistry, ExtensionPointRegistry extensionPointRegistry, TuscanyRuntime tuscanyRuntime) {
+ private Map<String, Contribution> loadedContributions = new ConcurrentHashMap<String, Contribution>();
+
+ private Map<String, DeployedComposite> startedComposites = new HashMap<String, DeployedComposite>();
+ private Map<String, DeployedComposite> stoppedComposites = new HashMap<String, DeployedComposite>();
+
+ public NodeImpl(String domainName,
+ Deployer deployer,
+ CompositeActivator compositeActivator,
+ DomainRegistry domainRegistry,
+ ExtensionPointRegistry extensionPointRegistry,
+ TuscanyRuntime tuscanyRuntime) {
this.domainName = domainName;
this.deployer = deployer;
this.compositeActivator = compositeActivator;
this.domainRegistry = domainRegistry;
this.extensionPointRegistry = extensionPointRegistry;
this.tuscanyRuntime = tuscanyRuntime;
+
+ domainRegistry.addContributionListener(new ContributionListener() {
+ public void contributionUpdated(String uri) {
+ loadedContributions.remove(uri);
+ }
+ public void contributionRemoved(String uri) {
+ loadedContributions.remove(uri);
+ }
+ });
}
public String installContribution(String contributionURL) throws ContributionReadException, ActivationException, ValidationException {
- return installContribution(null, contributionURL, null, null, true);
+ return installContribution(null, contributionURL, null, null);
}
- public String installContribution(String uri, String contributionURL, String metaDataURL, List<String> dependentContributionURIs, boolean startDeployables) throws ContributionReadException, ActivationException, ValidationException {
- // TODO: sort out deployables and exports
- org.apache.tuscany.sca.runtime.InstalledContribution ic = new org.apache.tuscany.sca.runtime.InstalledContribution(uri, contributionURL);
+ public String installContribution(String uri, String contributionURL) throws ContributionReadException, ActivationException, ValidationException {
+ return installContribution(uri, contributionURL, null, null);
+ }
+
+ public String installContribution(String uri, String contributionURL, String metaDataURL, List<String> dependentContributionURIs) throws ContributionReadException, ActivationException, ValidationException {
+ InstalledContribution ic = new InstalledContribution(uri, contributionURL);
+
+ if (dependentContributionURIs != null) {
+ ic.getDependentContributionURIs().addAll(dependentContributionURIs);
+ }
+
+ if (metaDataURL != null) {
+ mergeContributionMetaData(metaDataURL, loadContribution(ic));
+ }
+
peekIntoContribution(ic);
+
domainRegistry.installContribution(ic);
- if (startDeployables) {
- for (String compositeURI : ic.getDeployables()) {
- start(ic.getURI(), compositeURI);
- }
- // TODO: sort out metadata and dependents in distributed
- localInstall(ic.getURI(), contributionURL, metaDataURL, dependentContributionURIs, startDeployables);
- }
+
return ic.getURI();
}
-
+
+ public void installContribution(Contribution contribution, List<String> dependentContributionURIs) {
+ InstalledContribution ic = new InstalledContribution(contribution.getURI(), contribution.getLocation());
+ if (dependentContributionURIs != null) {
+ ic.getDependentContributionURIs().addAll(dependentContributionURIs);
+ }
+ ic.configureMetaData(contribution);
+ domainRegistry.installContribution(ic);
+ loadedContributions.put(ic.getURI(), contribution);
+ }
+
+ public void uninstallContribution(String contributionURI) {
+ domainRegistry.uninstallContribution(contributionURI);
+ }
+
+ protected void mergeContributionMetaData(String metaDataURL, Contribution contribution) throws ValidationException {
+ ContributionMetadata metaData;
+ Monitor monitor = deployer.createMonitor();
+ try {
+ metaData = deployer.loadXMLDocument(IOHelper.getLocationAsURL(metaDataURL), monitor);
+ } catch (Exception e) {
+ throw new ValidationException(e);
+ }
+ monitor.analyzeProblems();
+ contribution.mergeMetaData(metaData);
+ }
+
/**
+ * Peek into the contribution to find its attributes.
* ASM12032 and ASM12033 say no error checking should be done during install and that should happen later, but
- * we would still like to know about deployables and exports so peek into the contribution to try to get those,
+ * we need to know about deployables and exports so peek into the contribution to try to get those,
* and just ignore any errors they might happen while doing that.
*/
- protected void peekIntoContribution(org.apache.tuscany.sca.runtime.InstalledContribution ic) {
+ protected void peekIntoContribution(InstalledContribution ic) {
Contribution contribution = null;
try {
- contribution = deployer.loadContribution(IOHelper.createURI(ic.getURI()), IOHelper.getLocationAsURL(ic.getURI()), deployer.createMonitor());
+ contribution = loadContribution(ic);
} catch (Exception e) {
- // ignore any errors
+ // ignore it
}
+
if (contribution != null) {
- for (Composite composite : contribution.getDeployables()) {
- ic.getDeployables().add(composite.getURI());
- }
- // TODO: need to sort out if Export or xml goes in the reg
-// for (Export e : contribution.getExports()) {
-// }
+ ic.configureMetaData(contribution);
}
}
+
+ public List<String> getInstalledContributionURIs() {
+ return new ArrayList<String>(domainRegistry.getInstalledContributionURIs());
+ }
- private void localInstall(String uri, String contributionURL, String metaDataURL, List<String> dependentContributionURIs, boolean startDeployables) throws ContributionReadException, ValidationException, ActivationException {
- Monitor monitor = deployer.createMonitor();
- Contribution contribution = deployer.loadContribution(IOHelper.createURI(uri), IOHelper.getLocationAsURL(contributionURL), monitor);
- monitor.analyzeProblems();
- if (metaDataURL != null) {
- mergeContributionMetaData(metaDataURL, contribution);
- }
- installContribution(contribution, dependentContributionURIs, startDeployables);
+ public Contribution getContribution(String contributionURI) throws ContributionReadException, ValidationException {
+ return loadContribution(getInstalledContribution(contributionURI));
}
- private void mergeContributionMetaData(String metaDataURL, Contribution contribution) throws ValidationException {
- ContributionMetadata metaData;
- Monitor monitor = deployer.createMonitor();
- try {
- metaData = deployer.loadXMLDocument(IOHelper.getLocationAsURL(metaDataURL), monitor);
- } catch (Exception e) {
- throw new ValidationException(e);
- }
- monitor.analyzeProblems();
- contribution.mergeMetaData(metaData);
+ public List<String> getDeployableCompositeURIs(String contributionURI) {
+ InstalledContribution ic = domainRegistry.getInstalledContribution(contributionURI);
+ return new ArrayList<String>(ic.getDeployables());
}
- public String installContribution(Contribution contribution, List<String> dependentContributionURIs, boolean startDeployables) throws ContributionReadException, ActivationException, ValidationException {
- InstalledContribution ic = new InstalledContribution(contribution.getURI(), contribution.getLocation(), contribution, dependentContributionURIs);
- locallyInstalledContributions.put(contribution.getURI(), ic);
- if (startDeployables) {
- for (Composite c : ic.getDefaultDeployables()) {
- startComposite(c, ic);
- }
- } else {
- contribution.getDeployables().clear();
-
- List<Contribution> dependentContributions = calculateDependentContributions(ic);
+ public String addDeploymentComposite(String contributionURI, Reader compositeXML) throws ContributionReadException, XMLStreamException, ValidationException {
+ InstalledContribution ic = getInstalledContribution(contributionURI);
+
+ // load it to check its valid composite XML
+ Composite composite = deployer.loadXMLDocument(compositeXML);
+
+ return addDeploymentComposite(ic, composite);
+ }
- Monitor monitor = deployer.createMonitor();
- try {
- deployer.resolve(contribution, dependentContributions, monitor);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- monitor.analyzeProblems();
- }
- return ic.getURI();
+ public String addDeploymentComposite(String contributionURI, Composite composite) {
+ InstalledContribution ic = getInstalledContribution(contributionURI);
+ return addDeploymentComposite(ic, composite);
}
- protected List<Contribution> calculateDependentContributions(InstalledContribution ic) {
- List<Contribution> dependentContributions = new ArrayList<Contribution>();
- if (ic.getDependentContributionURIs() != null) {
- // if the install specified dependent uris use just those contributions
- for (String uri : ic.getDependentContributionURIs()) {
- InstalledContribution dependee = locallyInstalledContributions.get(uri);
- if (dependee != null) {
- dependentContributions.add(dependee.getContribution());
- }
- }
- } else {
- // otherwise use all available contributions for dependents
- for (InstalledContribution ics : locallyInstalledContributions.values()) {
- dependentContributions.add(ics.getContribution());
- }
+ protected String addDeploymentComposite(InstalledContribution ic, Composite composite) {
+ if (composite.getURI() == null || composite.getURI().length() < 1) {
+ composite.setURI(composite.getName().getLocalPart() + ".composite");
}
- return dependentContributions;
+ ic.getAdditionalDeployables().put(composite.getURI(), Utils.modelToXML(composite, false, extensionPointRegistry));
+ domainRegistry.updateInstalledContribution(ic);
+ return composite.getURI();
}
- public String start(String contributionURI, Reader compositeXML) throws ContributionReadException, XMLStreamException, ActivationException, ValidationException {
- Monitor monitor = deployer.createMonitor();
- Composite composite = deployer.loadXMLDocument(compositeXML, monitor);
- monitor.analyzeProblems();
- return start(contributionURI, composite);
- }
+ public void validateContribution(String contributionURI) throws ContributionReadException, ValidationException {
+ InstalledContribution ic = getInstalledContribution(contributionURI);
+ Contribution contribution = loadContribution(ic);
- public String start(String contributionURI, Composite composite) throws ActivationException, ValidationException {
- InstalledContribution ic = locallyInstalledContributions.get(contributionURI);
- if (ic == null) {
- throw new IllegalArgumentException("contribution not installed: " + contributionURI);
+ Monitor monitor = deployer.createMonitor();
+ try {
+ deployer.resolve(contribution, calculateDependentContributions(ic), monitor);
+ } catch (Exception e) {
+ loadedContributions.remove(ic.getURI());
+ throw new RuntimeException(e);
+ }
+ try {
+ monitor.analyzeProblems();
+ } catch (ValidationException e) {
+ loadedContributions.remove(ic.getURI());
+ throw e;
}
- String compositeArtifcatURI = deployer.attachDeploymentComposite(ic.getContribution(), composite, true);
- startComposite(composite, ic);
- return compositeArtifcatURI;
+ }
+
+ public Map<String, List<QName>> getStartedComposites() {
+ return domainRegistry.getRunningCompositeNames();
}
- public void start(String contributionURI, String compositeURI) throws ActivationException, ValidationException, ContributionReadException {
- InstalledContribution ic = locallyInstalledContributions.get(contributionURI);
- if (ic == null) {
-
- org.apache.tuscany.sca.runtime.InstalledContribution icx = domainRegistry.getInstalledContribution(contributionURI);
- String url = null;
- if (icx != null) {
- url = icx.getURL();
- }
- if (url == null) {
- throw new IllegalArgumentException("Contribution not installed: " + contributionURI);
- }
- localInstall(contributionURI, url, null, null, false);
- ic = locallyInstalledContributions.get(contributionURI);
+ public void startComposite(String contributionURI, String compositeURI) throws ActivationException, ValidationException, ContributionReadException {
+ String key = contributionURI+"/"+compositeURI;
+ if (startedComposites.containsKey(key)) {
+ throw new IllegalStateException("composite already started: " + compositeURI);
}
- if (!ic.restart(compositeURI)) {
- for (Artifact a : ic.getContribution().getArtifacts()) {
- if (a.getURI().equals(compositeURI)) {
- startComposite((Composite) a.getModel(), ic);
- return;
- }
- }
- throw new IllegalArgumentException("composite not found: " + compositeURI);
+ DeployedComposite dc = stoppedComposites.remove(key);
+ if (dc != null) {
+ dc.start();
+ startedComposites.put(key, dc);
+ } else {
+ InstalledContribution ic = getInstalledContribution(contributionURI);
+ Contribution contribution = loadContribution(ic);
+ Composite composite = contribution.getArtifactModel(compositeURI);
+ List<Contribution> dependentContributions = calculateDependentContributions(ic);
+ dc = new DeployedComposite(composite, contribution, dependentContributions, deployer, compositeActivator, domainRegistry, extensionPointRegistry);
+ dc.start();
+ startedComposites.put(key, dc);
}
}
-
- @Override
- public void stop(String contributionURI, String compositeURI) throws ActivationException {
- InstalledContribution ic = locallyInstalledContributions.get(contributionURI);
- if (ic == null) {
- throw new IllegalArgumentException("Contribution not installed: " + contributionURI);
+
+ public void stopComposite(String contributionURI, String compositeURI) throws ActivationException {
+ String key = contributionURI+"/"+compositeURI;
+ DeployedComposite dc = startedComposites.remove(key);
+ if (dc == null) {
+ throw new IllegalStateException("composite not started: " + compositeURI);
}
- ic.stop(compositeURI);
+ dc.stop();
+ stoppedComposites.put(key, dc);
}
- public Composite getDomainLevelComposite() {
+ public String getDomainName() {
+ return domainName;
+ }
+
+ public Composite getDomainComposite() {
FactoryExtensionPoint factories = extensionPointRegistry.getExtensionPoint(FactoryExtensionPoint.class);
AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class);
Composite domainComposite = assemblyFactory.createComposite();
- domainComposite.setName(new QName(Base.SCA11_TUSCANY_NS, "domainComposite"));
+ domainComposite.setName(new QName(Base.SCA11_TUSCANY_NS, domainName));
domainComposite.setAutowire(false);
domainComposite.setLocal(false);
List<Composite> domainIncludes = domainComposite.getIncludes();
@@ -270,292 +273,113 @@ public class NodeImpl implements Node {
return domainComposite;
}
- public String getDomainLevelCompositeAsString() {
- StAXArtifactProcessorExtensionPoint xmlProcessors = extensionPointRegistry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- StAXArtifactProcessor<Composite> compositeProcessor = xmlProcessors.getProcessor(Composite.class);
- XMLOutputFactory outputFactory = extensionPointRegistry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(XMLOutputFactory.class);
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- try {
- XMLStreamWriter sw = outputFactory.createXMLStreamWriter(bos);
- compositeProcessor.write(getDomainLevelComposite(), sw, new ProcessorContext(extensionPointRegistry));
- sw.close();
- } catch(Exception e) {
- throw new RuntimeException(e);
- }
-
- return bos.toString();
- }
- public Object getQNameDefinition(String contributionURI, QName definition, QName symbolSpace) {
- // TODO Auto-generated method stub
- return null;
+ public <T> T getService(Class<T> interfaze, String serviceURI) throws NoSuchServiceException {
+ return ServiceHelper.getService(interfaze, serviceURI, domainRegistry, extensionPointRegistry, deployer);
}
-
- public List<String> removeContribution(String contributionURI) throws ActivationException {
- domainRegistry.uninstallContribution(contributionURI);
-
- // TODO: should this next bit happen?
- List<String> removedContributionURIs = new ArrayList<String>();
- InstalledContribution ic = locallyInstalledContributions.get(contributionURI);
- if (ic != null) {
- removedContributionURIs.add(ic.getURI());
- for (String dependent : getDependentContributions(contributionURI)) {
- removedContributionURIs.addAll(removeContribution(dependent));
- }
- locallyInstalledContributions.remove(contributionURI);
- for (String compositeURI : ic.getStartedCompositeURIs()) {
- ic.stop(compositeURI);
- }
+
+ protected InstalledContribution getInstalledContribution(String contributionURI) {
+ InstalledContribution ic = domainRegistry.getInstalledContribution(contributionURI);
+ if (ic == null) {
+ throw new IllegalArgumentException("Contribution not installed: " + contributionURI);
}
- return removedContributionURIs;
+ return ic;
}
- public void updateContribution(String uri, String contributionURL) {
- // TODO Auto-generated method stub
- // is this just removeContribution/installContribution?
- }
- public void updateContribution(Contribution contribution) {
- // TODO Auto-generated method stub
- }
-
- public String updateDeploymentComposite(String uri, Reader compositeXML) {
- // TODO Auto-generated method stub
- // is this removeFromDomainLevelComposite/addDeploymentComposite
- return null;
- }
- public String updateDeploymentComposite(String uri, Composite composite) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public void stop() {
- ArrayList<String> ics = new ArrayList<String>(locallyInstalledContributions.keySet());
- for (String uri : ics) {
- try {
- removeContribution(uri);
- } catch (Exception e) {
- // TODO: log
- e.printStackTrace();
+ protected Contribution loadContribution(InstalledContribution ic) throws ContributionReadException, ValidationException {
+ Contribution contribution = loadedContributions.get(ic.getURI());
+ if (contribution == null) {
+ Monitor monitor = deployer.createMonitor();
+ contribution = deployer.loadContribution(IOHelper.createURI(ic.getURI()), IOHelper.getLocationAsURL(ic.getURL()), monitor);
+ monitor.analyzeProblems();
+ if (ic.getAdditionalDeployables().size() > 0) {
+ for (String uri : ic.getAdditionalDeployables().keySet()) {
+ String compositeXML = ic.getAdditionalDeployables().get(uri);
+ Composite composite;
+ try {
+ composite = deployer.loadXMLDocument(new StringReader(compositeXML));
+ } catch (XMLStreamException e) {
+ throw new ContributionReadException(e);
+ }
+ composite.setURI(composite.getName().getLocalPart() + ".composite");
+ contribution.addComposite(composite);
+ }
}
+ loadedContributions.put(ic.getURI(), contribution);
}
- if (tuscanyRuntime != null) {
- tuscanyRuntime.stop();
- }
+ return contribution;
}
- public <T> T getService(Class<T> interfaze, String serviceURI) throws NoSuchServiceException {
-
- List<Endpoint> endpoints = domainRegistry.findEndpoint(serviceURI);
- if (endpoints.size() < 1) {
- throw new NoSuchServiceException(serviceURI);
- }
-
- String serviceName = null;
- if (serviceURI.contains("/")) {
- int i = serviceURI.indexOf("/");
- if (i < serviceURI.length() - 1) {
- serviceName = serviceURI.substring(i + 1);
+ protected List<Contribution> calculateDependentContributions(InstalledContribution ic) throws ContributionReadException, ValidationException {
+ List<Contribution> dependentContributions = new ArrayList<Contribution>();
+ if (ic.getDependentContributionURIs() != null && ic.getDependentContributionURIs().size() > 0) {
+ // if the install specified dependent uris use just those contributions
+ for (String uri : ic.getDependentContributionURIs()) {
+ InstalledContribution dependee = domainRegistry.getInstalledContribution(uri);
+ if (dependee != null) {
+ dependentContributions.add(loadContribution(dependee));
+ }
}
- }
-
- Endpoint ep = endpoints.get(0);
- if (((RuntimeComponent)ep.getComponent()).getComponentContext() != null) {
- return ((RuntimeComponent)ep.getComponent()).getServiceReference(interfaze, serviceName).getService();
} else {
- return getRemoteProxy(interfaze, ep);
- }
- }
-
- private <T> T getRemoteProxy(Class<T> serviceInterface, Endpoint endpoint) throws NoSuchServiceException {
- FactoryExtensionPoint factories = extensionPointRegistry.getExtensionPoint(FactoryExtensionPoint.class);
- AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class);
- JavaInterfaceFactory javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
- ProxyFactory proxyFactory =
- new ExtensibleProxyFactory(extensionPointRegistry.getExtensionPoint(ProxyFactoryExtensionPoint.class));
-
- CompositeContext compositeContext =
- new CompositeContext(extensionPointRegistry, domainRegistry, null, null, null,
- deployer.getSystemDefinitions());
-
- RuntimeEndpointReference epr;
- try {
- epr =
- createEndpointReference(javaInterfaceFactory,
- compositeContext,
- assemblyFactory,
- endpoint,
- serviceInterface);
- } catch (Exception e) {
- throw new ServiceRuntimeException(e);
- }
-
- return proxyFactory.createProxy(serviceInterface, epr);
- }
-
- private RuntimeEndpointReference createEndpointReference(JavaInterfaceFactory javaInterfaceFactory,
- CompositeContext compositeContext,
- AssemblyFactory assemblyFactory,
- Endpoint endpoint,
- Class<?> businessInterface)
- throws CloneNotSupportedException, InvalidInterfaceException {
- Component component = endpoint.getComponent();
- ComponentService service = endpoint.getService();
- ComponentReference componentReference = assemblyFactory.createComponentReference();
- componentReference.setName("sca.client." + service.getName());
-
- componentReference.setCallback(service.getCallback());
- componentReference.getTargets().add(service);
- componentReference.getPolicySets().addAll(service.getPolicySets());
- componentReference.getRequiredIntents().addAll(service.getRequiredIntents());
- componentReference.getBindings().add(endpoint.getBinding());
-
- InterfaceContract interfaceContract = service.getInterfaceContract();
- Service componentTypeService = service.getService();
- if (componentTypeService != null && componentTypeService.getInterfaceContract() != null) {
- interfaceContract = componentTypeService.getInterfaceContract();
- }
- interfaceContract = getInterfaceContract(javaInterfaceFactory, interfaceContract, businessInterface);
- componentReference.setInterfaceContract(interfaceContract);
- componentReference.setMultiplicity(Multiplicity.ONE_ONE);
- // component.getReferences().add(componentReference);
-
- // create endpoint reference
- EndpointReference endpointReference = assemblyFactory.createEndpointReference();
- endpointReference.setComponent(component);
- endpointReference.setReference(componentReference);
- endpointReference.setBinding(endpoint.getBinding());
- endpointReference.setUnresolved(false);
- endpointReference.setStatus(EndpointReference.Status.WIRED_TARGET_FOUND_AND_MATCHED);
-
- endpointReference.setTargetEndpoint(endpoint);
-
- componentReference.getEndpointReferences().add(endpointReference);
- ((RuntimeComponentReference)componentReference).setComponent((RuntimeComponent)component);
- ((RuntimeEndpointReference)endpointReference).bind(compositeContext);
-
- return (RuntimeEndpointReference)endpointReference;
- }
-
- private InterfaceContract getInterfaceContract(JavaInterfaceFactory javaInterfaceFactory,
- InterfaceContract interfaceContract,
- Class<?> businessInterface) throws CloneNotSupportedException,
- InvalidInterfaceException {
- if (businessInterface == null) {
- return interfaceContract;
- }
- boolean compatible = false;
- if (interfaceContract != null && interfaceContract.getInterface() != null) {
- Interface interfaze = interfaceContract.getInterface();
- if (interfaze instanceof JavaInterface) {
- Class<?> cls = ((JavaInterface)interfaze).getJavaClass();
- if (cls != null && businessInterface.isAssignableFrom(cls)) {
- compatible = true;
+ for (Import imprt : loadContribution(ic).getImports()) {
+ for (InstalledContribution exportingIC : findExportingContributions(imprt)) {
+ dependentContributions.add(loadContribution(exportingIC));
}
}
}
-
- if (!compatible) {
- // The interface is not assignable from the interface contract
- interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
- JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(businessInterface);
- interfaceContract.setInterface(callInterface);
- if (callInterface.getCallbackClass() != null) {
- interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(callInterface
- .getCallbackClass()));
- }
- }
-
- return interfaceContract;
- }
-
- public String getDomainName() {
- return domainName;
+ // TODO: there is also the location attribute on the import which should be taken into account
+ return dependentContributions;
}
- public List<String> getStartedCompositeURIs(String contributionURI) {
- InstalledContribution ic = locallyInstalledContributions.get(contributionURI);
- if (ic == null) {
- throw new IllegalArgumentException("no contribution found for: " + contributionURI);
+ private List<InstalledContribution> findExportingContributions(Import imprt) {
+ List<InstalledContribution> ics = new ArrayList<InstalledContribution>();
+ // TODO: Handle Imports in a more extensible way
+ for (String curi : domainRegistry.getInstalledContributionURIs()) {
+ InstalledContribution ic = domainRegistry.getInstalledContribution(curi);
+ if (imprt instanceof JavaImport) {
+ for (String s : ic.getJavaExports()) {
+ if (s.startsWith(((JavaImport)imprt).getPackage())) {
+ ics.add(ic);
+ }
+ }
+ } else if (imprt instanceof NamespaceImport) {
+ if (ic.getNamespaceExports().contains(((NamespaceImport)imprt).getNamespace())) {
+ ics.add(ic);
+ }
+ }
}
- return ic.getStartedCompositeURIs();
+ return ics;
}
-
- public List<String> getInstalledContributionURIs() {
- Set<String> ls = new HashSet<String>(domainRegistry.getInstalledContributionURIs());
- ls.addAll(locallyInstalledContributions.keySet());
- return new ArrayList<String>(ls);
- }
-
- public Contribution getInstalledContribution(String uri) {
- if (locallyInstalledContributions.containsKey(uri)) {
- return locallyInstalledContributions.get(uri).getContribution();
- }
- throw new IllegalArgumentException("no contribution found for: " + uri);
+
+ @Override
+ public Object getQNameDefinition(String contributionURI, QName definition, QName symbolSpace) {
+ // TODO Auto-generated method stub
+ return null;
}
- protected String getContributionUriForArtifact(String artifactURI) {
- String contributionURI = null;
- for (String uri : locallyInstalledContributions.keySet()) {
- if (artifactURI.startsWith(uri)) {
- contributionURI = uri;
- break;
- }
- }
- if (contributionURI == null) {
- throw new IllegalArgumentException("no contribution found for: " + artifactURI);
+ @Override
+ public List<String> startDeployables(String contributionURI) throws ActivationException, ValidationException, ContributionReadException {
+ List<String> dcURIs = getDeployableCompositeURIs(contributionURI);
+ for (String dcURI : dcURIs) {
+ startComposite(contributionURI, dcURI);
}
- return contributionURI;
+ return dcURIs;
}
- protected void startComposite(Composite c, InstalledContribution ic) throws ActivationException, ValidationException {
- List<Contribution> dependentContributions = calculateDependentContributions(ic);
- DeployedComposite dc = new DeployedComposite(c, ic.getContribution(), dependentContributions, deployer, compositeActivator, domainRegistry, extensionPointRegistry);
- ic.start(dc);
+ // TODO: this is used by the shell to endpoint detail, should it be on the Node interface?
+ public DomainRegistry getEndpointRegistry() {
+ return domainRegistry;
}
- public Set<String> getDependentContributions(String contributionURI) {
- InstalledContribution ic = locallyInstalledContributions.get(contributionURI);
- if (ic == null) {
- throw new IllegalArgumentException("Contribution not installed: " + contributionURI);
- }
- Set<String> dependentContributionURIs = new HashSet<String>();
- for (InstalledContribution icx : locallyInstalledContributions.values()) {
- if (ic != icx) {
- List<Contribution> dependencies = icx.getContribution().getDependencies();
- if (dependencies != null && dependencies.contains(ic.getContribution())) {
- dependentContributionURIs.addAll(getDependentContributions(icx.getURI()));
- }
- }
- }
- return dependentContributionURIs;
- }
-
- /**
- * Returns a default URI for a contribution based on the contribution URL
- */
- protected String getDefaultContributionURI(String contributionURL) {
- String uri = null;
- try {
- File f = new File(contributionURL);
- if ("classes".equals(f.getName()) && "target".equals(f.getParentFile().getName())) {
- uri = f.getParentFile().getParentFile().getName();
- } else {
- uri = f.getName();
+ public void stop() {
+ for (DeployedComposite dc : startedComposites.values()) {
+ try {
+ dc.stop();
+ } catch (ActivationException e) {
}
- } catch (Exception e) {
- // ignore
}
- if (uri == null) {
- uri = contributionURL;
- }
- if (uri.endsWith(".zip") || uri.endsWith(".jar")) {
- uri = uri.substring(0, uri.length()-4);
- }
- return uri;
+ startedComposites.clear();
+ startedComposites.clear();
+
}
- public DomainRegistry getEndpointRegistry() {
- return domainRegistry;
- }
-
}