summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-07-14 17:13:26 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-07-14 17:13:26 +0000
commit2e47a0cdf5eec96d282d31319c404bfc6fb0bc92 (patch)
treea6805856ad5129335fc7fcf29166dbc8658fe8c4
parent9e569d19c4305f332d4f4b11413c052dbc9f05b6 (diff)
Fix for TUSCANY-2409. Mirrored changes to SCANodeFactory in NodeLauncher.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@676650 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherBootstrap.java11
-rw-r--r--java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/Contribution.java48
-rw-r--r--java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java82
-rw-r--r--java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java13
-rw-r--r--java/sca/samples/calculator-distributed/src/main/java/node/LaunchCalculatorNodeA.java2
-rw-r--r--java/sca/samples/domain-management/src/main/java/manager/DistributeAndRunComponents.java4
-rw-r--r--java/sca/tutorial/store-client/launch/LaunchStoreClientNode.java2
7 files changed, 112 insertions, 50 deletions
diff --git a/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherBootstrap.java b/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherBootstrap.java
index f997d26cac..06b1966c57 100644
--- a/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherBootstrap.java
+++ b/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherBootstrap.java
@@ -97,6 +97,17 @@ public class NodeImplementationLauncherBootstrap {
/**
* Bootstrap a new SCA node.
*
+ * @param configurationURI
+ * @param contributionClassLoader
+ */
+ public NodeImplementationLauncherBootstrap(String compositeURI, ClassLoader contributionClassLoader) throws Exception {
+ SCANode2Factory nodeFactory = SCANode2Factory.newInstance();
+ node = new NodeFacade(nodeFactory.createSCANodeFromClassLoader(compositeURI, contributionClassLoader));
+ }
+
+ /**
+ * Bootstrap a new SCA node.
+ *
* @param compositeURI
* @param uris
* @param locations
diff --git a/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/Contribution.java b/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/Contribution.java
new file mode 100644
index 0000000000..4f4f861e2f
--- /dev/null
+++ b/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/Contribution.java
@@ -0,0 +1,48 @@
+/*
+ * 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.node.launcher;
+
+/**
+ * Represents an SCA contribution uri + location.
+ *
+ * @version $Rev$ $Date$
+ */
+public final class Contribution {
+ private String uri;
+ private String location;
+
+ /**
+ * Constructs a new SCA contribution.
+ *
+ * @param uri
+ * @param location
+ */
+ public Contribution(String uri, String location) {
+ this.uri = uri;
+ this.location = location;
+ }
+
+ public String getURI() {
+ return uri;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+} \ No newline at end of file
diff --git a/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java b/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java
index 1ba784420f..60c50c6919 100644
--- a/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java
+++ b/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java
@@ -50,66 +50,62 @@ public class NodeLauncher {
}
/**
- * Creates a new node.
+ * Creates a new SCA node from the configuration URL
*
- * @param configurationURI
- * @return a new node
+ * @param configurationURL the URL of the node configuration which is the ATOM feed
+ * that contains the URI of the composite and a collection of URLs for the contributions
+ *
+ * @return a new SCA node.
* @throws LauncherException
*/
- public <T> T createNode(String configurationURI) throws LauncherException {
- return (T)node(configurationURI, null, null, null);
+ public <T> T createNodeFromURL(String configurationURL) throws LauncherException {
+ return (T)node(configurationURL, null, null, null, null);
}
/**
- * Represents an SCA contribution uri + location.
+ * Creates a new SCA Node.
+ *
+ * @param compositeURI the URI of the composite to use
+ * @param contributions the URI of the contributions that provides the composites and related
+ * artifacts. If the list is empty, then we will use the thread context classloader to discover
+ * the contribution on the classpath
+ *
+ * @return a new SCA node.
+ * @throws LauncherException
*/
- public static final class Contribution {
- private String uri;
- private String location;
-
- /**
- * Constructs a new SCA contribution.
- *
- * @param uri
- * @param location
- */
- public Contribution(String uri, String location) {
- this.uri = uri;
- this.location = location;
- }
-
- public String getURI() {
- return uri;
- }
-
- public String getLocation() {
- return location;
- }
+ public <T> T createNode(String compositeURI, Contribution...contributions) throws LauncherException {
+ return (T)node(null, compositeURI, null, contributions, null);
}
/**
- * Creates a new Node.
+ * Creates a new SCA Node.
*
- * @param compositeURI
- * @param contributions
- * @return a new node
+ * @param compositeURI the URI of the composite to use
+ * @param compositeContent the XML content of the composite to use
+ * @param contributions the URI of the contributions that provides the composites and related artifacts
+ * @return a new SCA node.
* @throws LauncherException
*/
- public <T> T createNode(String compositeURI, Contribution...contributions) throws LauncherException {
- return (T)node(null, compositeURI, null, contributions);
+ public <T> T createNode(String compositeURI, String compositeContent, Contribution...contributions) throws LauncherException {
+ return (T)node(null, compositeURI, compositeContent, contributions, null);
}
/**
- * Creates a new Node.
+ * Create a SCA node based on the discovery of the contribution on the classpath for the
+ * given classloader. This method should be treated a convenient shortcut with the following
+ * assumptions:
+ * <ul>
+ * <li>This is a standalone application and there is a deployable composite file on the classpath.
+ * <li>There is only one contribution which contains the deployable composite file physically in its packaging hierarchy.
+ * </ul>
*
- * @param compositeURI
- * @param compositeContent
- * @param contributions
- * @return a new node
- * @throws LauncherException
+ * @param compositeURI The URI of the composite file relative to the root of the enclosing contribution
+ * @param classLoader The ClassLoader used to load the composite file as a resource. If the value is null,
+ * then thread context classloader will be used
+ * @return A newly created SCA node
*/
- public <T> T createNode(String compositeURI, String compositeContent, Contribution...contributions) throws LauncherException {
- return (T)node(null, compositeURI, compositeContent, contributions);
+ public <T> T createSCANodeFromClassLoader(String compositeURI, ClassLoader classLoader) throws LauncherException {
+ return (T)node(null, compositeURI, null, null, classLoader);
}
public static void main(String[] args) throws Exception {
@@ -119,7 +115,7 @@ public class NodeLauncher {
NodeLauncher launcher = newInstance();
String configurationURI = args[0];
logger.info("SCA Node configuration: " + configurationURI);
- Object node = launcher.createNode(configurationURI);
+ Object node = launcher.createNodeFromURL(configurationURI);
// Start the node
try {
diff --git a/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java b/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
index 2a208d4c07..5580d14e74 100644
--- a/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
+++ b/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
@@ -312,7 +312,7 @@ final class NodeLauncherUtil {
* @param contributions
* @throws LauncherException
*/
- static Object node(String configurationURI, String compositeURI, String compositeContent, NodeLauncher.Contribution[] contributions) throws LauncherException {
+ static Object node(String configurationURI, String compositeURI, String compositeContent, Contribution[] contributions, ClassLoader contributionClassLoader) throws LauncherException {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
@@ -339,10 +339,16 @@ final class NodeLauncherUtil {
// Construct the node with a configuration URI
bootstrap = bootstrapClass.getConstructor(String.class).newInstance(configurationURI);
+ } else if (contributionClassLoader != null) {
+
+ // Construct the node with a compositeURI and a classloader
+ Constructor<?> constructor = bootstrapClass.getConstructor(String.class, ClassLoader.class);
+ bootstrap = constructor.newInstance(compositeURI, contributionClassLoader);
+
} else if (compositeContent != null) {
- // Construct the node with a composite URI and the URIs and
- // locations of a list of contributions
+ // Construct the node with a composite URI, the composite content and
+ // the URIs and locations of a list of contributions
Constructor<?> constructor = bootstrapClass.getConstructor(String.class, String.class, String[].class, String[].class);
String[] uris = new String[contributions.length];
String[] locations = new String[contributions.length];
@@ -351,6 +357,7 @@ final class NodeLauncherUtil {
locations[i] = contributions[i].getLocation();
}
bootstrap = constructor.newInstance(compositeURI, compositeContent, uris, locations);
+
} else {
// Construct the node with a composite URI and the URIs and
diff --git a/java/sca/samples/calculator-distributed/src/main/java/node/LaunchCalculatorNodeA.java b/java/sca/samples/calculator-distributed/src/main/java/node/LaunchCalculatorNodeA.java
index b61d1da85d..0025c85f79 100644
--- a/java/sca/samples/calculator-distributed/src/main/java/node/LaunchCalculatorNodeA.java
+++ b/java/sca/samples/calculator-distributed/src/main/java/node/LaunchCalculatorNodeA.java
@@ -33,7 +33,7 @@ public class LaunchCalculatorNodeA {
try {
NodeLauncher nodeLauncher = NodeLauncher.newInstance();
- node = nodeLauncher.createNode("http://localhost:9990/node-config/NodeA");
+ node = nodeLauncher.createNodeFromURL("http://localhost:9990/node-config/NodeA");
node.start();
diff --git a/java/sca/samples/domain-management/src/main/java/manager/DistributeAndRunComponents.java b/java/sca/samples/domain-management/src/main/java/manager/DistributeAndRunComponents.java
index cb61540ab1..7981cdb5c6 100644
--- a/java/sca/samples/domain-management/src/main/java/manager/DistributeAndRunComponents.java
+++ b/java/sca/samples/domain-management/src/main/java/manager/DistributeAndRunComponents.java
@@ -281,10 +281,10 @@ public class DistributeAndRunComponents {
// Create the SCA node, give it the composite and the list of contributions
// to use
List<Contribution> dependencies = nodeDependencies.get(node);
- org.apache.tuscany.sca.node.launcher.NodeLauncher.Contribution[] contributions = new org.apache.tuscany.sca.node.launcher.NodeLauncher.Contribution[dependencies.size()];
+ org.apache.tuscany.sca.node.launcher.Contribution[] contributions = new org.apache.tuscany.sca.node.launcher.Contribution[dependencies.size()];
for (int c =0, n = dependencies.size(); c < n; c++) {
Contribution dependency = dependencies.get(c);
- contributions[c] = new org.apache.tuscany.sca.node.launcher.NodeLauncher.Contribution(dependency.getURI(), dependency.getLocation());
+ contributions[c] = new org.apache.tuscany.sca.node.launcher.Contribution(dependency.getURI(), dependency.getLocation());
}
SCANode2 runtimeNode = launcher.createNode("http://sample/" + node.getName(), print(runnable), contributions);
diff --git a/java/sca/tutorial/store-client/launch/LaunchStoreClientNode.java b/java/sca/tutorial/store-client/launch/LaunchStoreClientNode.java
index 4709240db5..8dd1429890 100644
--- a/java/sca/tutorial/store-client/launch/LaunchStoreClientNode.java
+++ b/java/sca/tutorial/store-client/launch/LaunchStoreClientNode.java
@@ -29,7 +29,7 @@ public class LaunchStoreClientNode {
public static void main(String[] args) throws Exception {
NodeLauncher nodeLauncher = NodeLauncher.newInstance();
- SCANode2 storeClientNode = nodeLauncher.createNode("http://localhost:9990/node-config/StoreClientNode");
+ SCANode2 storeClientNode = nodeLauncher.createNodeFromURL("http://localhost:9990/node-config/StoreClientNode");
storeClientNode.start();
SCAClient client = (SCAClient)storeClientNode;