summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/Section10.java3
-rw-r--r--sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/Section10Factory.java150
-rw-r--r--sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/DeployedComposite.java28
-rw-r--r--sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Helper.java57
-rw-r--r--sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/InstalledContribution.java5
-rw-r--r--sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java41
6 files changed, 183 insertions, 101 deletions
diff --git a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/Section10.java b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/Section10.java
index 6d4b49d53d..845145718c 100644
--- a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/Section10.java
+++ b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/Section10.java
@@ -210,8 +210,9 @@ public interface Section10 {
/**
* Probably want to be able to stop it all at once so a method called stop or shutdown or destroy
* though i guess it could be argued that this method may be somewhere else
+ * @throws ActivationException
*/
- void shutdown();
+ void shutdown() throws ActivationException;
/**
* Would also be convenient to get service proxys as from SCAClientFactory
diff --git a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/Section10Factory.java b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/Section10Factory.java
index 5824e5e494..c9600578cf 100644
--- a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/Section10Factory.java
+++ b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/Section10Factory.java
@@ -19,20 +19,158 @@
package org.apache.tuscany.sca.something;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.deployment.Deployer;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.apache.tuscany.sca.node.impl.NodeFactoryImpl;
+import org.apache.tuscany.sca.runtime.CompositeActivator;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
+import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory;
import org.apache.tuscany.sca.something.impl.Section10Impl;
+import org.oasisopen.sca.ServiceRuntimeException;
public class Section10Factory {
+ private NodeFactoryImpl nodeFactory;
+ private Deployer deployer;
+ private ExtensionPointRegistry extensionPointRegistry;
+ private MonitorFactory monitorFactory;
+ private CompositeActivator compositeActivator;
+ private ExtensibleDomainRegistryFactory domainRegistryFactory;
+
public static Section10 createSection10() {
- Properties defaultConfig = new Properties();
- defaultConfig.setProperty("defaultScheme", "vm");
- defaultConfig.setProperty("defaultDomainName", "default");
- return new Section10Impl(defaultConfig);
+ return new Section10Factory().createSection10("default");
+ }
+
+ public Section10Factory() {
+ init(null);
+ }
+
+ public Section10Factory(String configURI) {
+ Properties properties;
+ if (configURI == null || configURI.length() < 1) {
+ properties = null;
+ } else if (configURI.startsWith("properties:")) {
+ try {
+ properties = loadProperties(configURI.substring("properties:".length()));
+ } catch (IOException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ } else if (configURI.startsWith("uri:")) {
+ properties = parseConfigURI(configURI.substring("uri:".length()));
+ } else {
+ properties = new Properties();
+ properties.setProperty("defaultDomainName", configURI);
+ }
+ init(properties);
+ }
+
+ public Section10Factory(Properties config) {
+ init(config);
+ }
+
+ public Section10 createSection10(String domainName) {
+ EndpointRegistry endpointRegistry = domainRegistryFactory.getEndpointRegistry("default", domainName);
+ return new Section10Impl(domainName, deployer, monitorFactory, compositeActivator, endpointRegistry, extensionPointRegistry);
+ }
+
+ public void shutdown() {
+ nodeFactory.destroy();
}
- public static Section10 createSection10(Properties config) {
- return new Section10Impl(config);
+ protected void init(Properties config) {
+ if (config == null) {
+ config = new Properties();
+ config.setProperty("defaultScheme", "vm");
+ config.setProperty("defaultDomainName", "default");
+ }
+ this.nodeFactory = (NodeFactoryImpl)NodeFactory.newInstance(config);
+ nodeFactory.start();
+ this.deployer = nodeFactory.getDeployer();
+ this.extensionPointRegistry = nodeFactory.getExtensionPointRegistry();
+ UtilityExtensionPoint utilities = extensionPointRegistry.getExtensionPoint(UtilityExtensionPoint.class);
+ this.monitorFactory = utilities.getUtility(MonitorFactory.class);
+ this.compositeActivator = utilities.getUtility(CompositeActivator.class);
+ this.domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(extensionPointRegistry);
+ }
+
+ /**
+ * Parse the config string into a Properties object.
+ * The config URI has the following format:
+ * uri:<domainName>?name=value&...
+ */
+ private static Properties parseConfigURI(String configURI) {
+ Properties properties = new Properties();
+ int qm = configURI.indexOf('?');
+ if (qm < 0) {
+ properties.setProperty("defaultDomainName", configURI);
+ } else {
+ if (qm == 0) {
+ properties.setProperty("defaultDomainName", "default");
+ } else {
+ properties.setProperty("defaultDomainName", configURI.substring(0, qm));
+ }
+ if (configURI.length() > qm+1) {
+ Map<String, String> params = new HashMap<String, String>();
+ for (String param : configURI.substring(qm+1).split("&")) {
+ String[] px = param.split("=");
+ if (px.length == 2) {
+ params.put(px[0], px[1]);
+ } else {
+ params.put(px[0], "");
+ }
+ }
+ for (String name : params.keySet()) {
+ properties.setProperty(name, params.get(name));
+ }
+ }
+ }
+ return properties;
+ }
+
+ /**
+ * load the properties from external URL or a relative file
+ * properties:<url to properties file>
+ */
+ private static Properties loadProperties(String propsURL) throws IOException {
+
+ Properties properties = new Properties();
+ File file = new File(propsURL);
+
+ InputStream inputStream = null;
+ if (file.exists()) {
+ inputStream = new FileInputStream(file);
+ } else {
+ URL url = null;
+ try {
+ url = new URL(propsURL);
+ } catch (MalformedURLException e) {
+ inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(propsURL);
+ if (inputStream == null) {
+ throw new IOException("File does not exist: " + propsURL + ", could not be found on the classpath and is not a valid URL: " + e);
+ }
+ }
+ if (inputStream == null && url != null) {
+ inputStream = url.openStream();
+ }
+ }
+ if (inputStream != null) {
+ properties.load(inputStream);
+ inputStream.close();
+ }
+
+ return properties;
}
}
diff --git a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/DeployedComposite.java b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/DeployedComposite.java
index 09d59589d9..4f6f3f8b9f 100644
--- a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/DeployedComposite.java
+++ b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/DeployedComposite.java
@@ -43,9 +43,9 @@ import org.oasisopen.sca.ServiceRuntimeException;
public class DeployedComposite {
private String uri;
- private Composite c;
- private InstalledContribution ic;
- private List<Contribution> dependedOnContributionURIs;
+ private Composite composite;
+ private InstalledContribution installedContribution;
+ private List<Contribution> dependedOnContributions;
private Composite domainComposite; // TODO: this is misleadingly named
private CompositeActivator compositeActivator;
@@ -55,17 +55,17 @@ public class DeployedComposite {
private EndpointRegistry endpointRegistry;
private ExtensionPointRegistry extensionPointRegistry;
- public DeployedComposite(Composite c,
+ public DeployedComposite(Composite composite,
InstalledContribution ic,
- List<Contribution> dependedOnContributionURIs,
+ List<Contribution> dependedOnContributions,
Deployer deployer,
CompositeActivator compositeActivator,
MonitorFactory monitorFactory,
EndpointRegistry endpointRegistry,
ExtensionPointRegistry extensionPointRegistry) throws ActivationException {
- this.c = c;
- this.ic = ic;
- this.dependedOnContributionURIs = dependedOnContributionURIs;
+ this.composite = composite;
+ this.installedContribution = ic;
+ this.dependedOnContributions = dependedOnContributions;
this.deployer = deployer;
this.compositeActivator = compositeActivator;
this.monitorFactory = monitorFactory;
@@ -80,16 +80,16 @@ public class DeployedComposite {
protected void init() throws Throwable {
- List<Contribution> contributions = new ArrayList<Contribution>();
- contributions.add(ic.getContribution());
- contributions.get(0).getDeployables().clear();
- contributions.get(0).getDeployables().add(c);
+ List<Contribution> contribution = new ArrayList<Contribution>();
+ contribution.add(installedContribution.getContribution());
+ contribution.get(0).getDeployables().clear();
+ contribution.get(0).getDeployables().add(composite);
Monitor monitor = monitorFactory.createMonitor();
Monitor tcm = monitorFactory.setContextMonitor(monitor);
try {
- domainComposite = deployer.build(contributions, dependedOnContributionURIs, new HashMap<QName, List<String>>(), monitor);
+ domainComposite = deployer.build(contribution, dependedOnContributions, new HashMap<QName, List<String>>(), monitor);
analyzeProblems(monitor);
} finally {
@@ -108,7 +108,7 @@ public class DeployedComposite {
compositeActivator.activate(compositeContext, domainComposite);
compositeActivator.start(compositeContext, domainComposite);
- this.uri = getCompositeURI(c, ic);
+ this.uri = getCompositeURI(composite, installedContribution);
}
public void unDeploy() throws ActivationException {
diff --git a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Helper.java b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Helper.java
deleted file mode 100644
index a8a06ed00b..0000000000
--- a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Helper.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tuscany.sca.something.impl;
-
-import java.util.List;
-
-import org.apache.tuscany.sca.assembly.Composite;
-import org.apache.tuscany.sca.contribution.Contribution;
-import org.apache.tuscany.sca.core.UtilityExtensionPoint;
-import org.apache.tuscany.sca.monitor.MonitorFactory;
-import org.apache.tuscany.sca.node.impl.NodeFactoryImpl;
-import org.apache.tuscany.sca.runtime.ActivationException;
-import org.apache.tuscany.sca.runtime.CompositeActivator;
-import org.apache.tuscany.sca.runtime.DomainRegistryFactory;
-import org.apache.tuscany.sca.runtime.EndpointRegistry;
-import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory;
-
-public class Helper {
-
- public static DeployedComposite createDeployedComposite(Composite composite,
- InstalledContribution ic,
- List<Contribution> dependentContributions,
- String domainName,
- NodeFactoryImpl nodeFactory) throws ActivationException {
-
- // TODO: have this code as a separate static method for now to keep the impl class clean while its worked out what it needs
-
- UtilityExtensionPoint utilities = nodeFactory.getExtensionPointRegistry().getExtensionPoint(UtilityExtensionPoint.class);
- CompositeActivator compositeActivator = utilities.getUtility(CompositeActivator.class);
- MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
-
- DomainRegistryFactory domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(nodeFactory.getExtensionPointRegistry());
- EndpointRegistry endpointRegistry = domainRegistryFactory.getEndpointRegistry("default", domainName);
-
- return new DeployedComposite(composite, ic, dependentContributions, nodeFactory.getDeployer(),
- compositeActivator, monitorFactory, endpointRegistry,
- nodeFactory.getExtensionPointRegistry());
- }
-
-}
diff --git a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/InstalledContribution.java b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/InstalledContribution.java
index c664415c0f..69dc9e6992 100644
--- a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/InstalledContribution.java
+++ b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/InstalledContribution.java
@@ -27,8 +27,6 @@ import org.apache.tuscany.sca.contribution.Contribution;
public class InstalledContribution {
- // TODO: could this instead just be org.apache.tuscany.sca.contribution.Contribution?
-
private String uri;
private String url;
private Contribution contribution;
@@ -59,7 +57,4 @@ public class InstalledContribution {
public List<DeployedComposite> getDeployedComposites() {
return deployedComposites;
}
-
- // TODO: there likely needs to be ways to get at depending/dependent contributions
-
}
diff --git a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java
index aa12fe8716..183591e9bf 100644
--- a/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java
+++ b/sca-java-2.x/contrib/modules/section10/src/main/java/org/apache/tuscany/sca/something/impl/Section10Impl.java
@@ -27,7 +27,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.Set;
import javax.xml.namespace.QName;
@@ -38,13 +37,13 @@ import org.apache.tuscany.sca.common.java.io.IOHelper;
import org.apache.tuscany.sca.contribution.Artifact;
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
-import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.deployment.Deployer;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
-import org.apache.tuscany.sca.node.NodeFactory;
-import org.apache.tuscany.sca.node.impl.NodeFactoryImpl;
import org.apache.tuscany.sca.runtime.ActivationException;
+import org.apache.tuscany.sca.runtime.CompositeActivator;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
import org.apache.tuscany.sca.something.Section10;
import org.oasisopen.sca.NoSuchDomainException;
import org.oasisopen.sca.NoSuchServiceException;
@@ -52,16 +51,21 @@ import org.oasisopen.sca.client.SCAClientFactory;
public class Section10Impl implements Section10 {
- protected NodeFactoryImpl nodeFactory;
- protected Deployer deployer;
- protected Map<String, InstalledContribution> installedContributions = new HashMap<String, InstalledContribution>();
- protected MonitorFactory monitorFactory;
+ private String domainName;
+ private Deployer deployer;
+ private Map<String, InstalledContribution> installedContributions = new HashMap<String, InstalledContribution>();
+ private MonitorFactory monitorFactory;
+ private CompositeActivator compositeActivator;
+ private EndpointRegistry endpointRegistry;
+ private ExtensionPointRegistry extensionPointRegistry;
- public Section10Impl(Properties config) {
- this.nodeFactory = (NodeFactoryImpl)NodeFactory.newInstance(config);
- ((NodeFactoryImpl)nodeFactory).start();
- this.deployer = nodeFactory.getDeployer();
- this.monitorFactory = nodeFactory.getExtensionPointRegistry().getExtensionPoint(UtilityExtensionPoint.class).getUtility(MonitorFactory.class);
+ public Section10Impl(String domainName, Deployer deployer, MonitorFactory monitorFactory, CompositeActivator compositeActivator, EndpointRegistry endpointRegistry, ExtensionPointRegistry extensionPointRegistry) {
+ this.domainName = domainName;
+ this.deployer = deployer;
+ this.monitorFactory = monitorFactory;
+ this.compositeActivator = compositeActivator;
+ this.endpointRegistry = endpointRegistry;
+ this.extensionPointRegistry = extensionPointRegistry;
}
public String installContribution(String contributionURL) throws ContributionReadException, ActivationException {
@@ -183,8 +187,10 @@ public class Section10Impl implements Section10 {
return null;
}
- public void shutdown() {
- nodeFactory.destroy();
+ public void shutdown() throws ActivationException {
+ for (String uri : installedContributions.keySet()) {
+ removeContribution(uri);
+ }
}
public <T> T getService(Class<T> interfaze, String serviceURI) throws NoSuchServiceException {
@@ -197,8 +203,7 @@ public class Section10Impl implements Section10 {
}
public String getDomainName() {
- // TODO Auto-generated method stub
- return "default";
+ return domainName;
}
public List<String> getDeployedCompostes(String contributionURI) {
@@ -235,7 +240,7 @@ public class Section10Impl implements Section10 {
dependentContributions.add(ics.getContribution());
}
- DeployedComposite dc = Helper.createDeployedComposite(c, ic, dependentContributions, getDomainName(), nodeFactory);
+ DeployedComposite dc = new DeployedComposite(c, ic, dependentContributions, deployer, compositeActivator, monitorFactory, endpointRegistry, extensionPointRegistry);
ic.getDeployedComposites().add(dc);
}