diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2011-01-12 08:56:52 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2011-01-12 08:56:52 +0000 |
commit | 9a4d83faf250efb00160c20c05fb727ad92c555c (patch) | |
tree | a249e7ad5933517b6f1f6c0c239547289a62e2b9 /sca-java-2.x/trunk | |
parent | e30d27ecbcbfa0c5f08299af755a38f2c2365db0 (diff) |
Update to create a service proxy directly instead of using the sca client factory api and update testcases for that, and rename package
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1058025 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk')
14 files changed, 87 insertions, 48 deletions
diff --git a/sca-java-2.x/trunk/modules/domain-node/pom.xml b/sca-java-2.x/trunk/modules/domain-node/pom.xml index b4980b2105..20d21e0b31 100644 --- a/sca-java-2.x/trunk/modules/domain-node/pom.xml +++ b/sca-java-2.x/trunk/modules/domain-node/pom.xml @@ -44,12 +44,6 @@ <version>2.0-SNAPSHOT</version> </dependency> - <dependency> - <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-sca-client-impl</artifactId> - <version>2.0-SNAPSHOT</version> - </dependency> - <dependency> <groupId>org.apache.tuscany.sca</groupId> <artifactId>tuscany-implementation-java-runtime</artifactId> diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/Node.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/runtime/Node.java index 9a82997a33..5e9d9973c3 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/Node.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/runtime/Node.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.tuscany.sca.node2; +package org.apache.tuscany.sca.runtime; import java.io.Reader; import java.util.List; diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/NodeFactory.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/runtime/NodeFactory.java index 999311b05d..2e8e29a05b 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/NodeFactory.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/runtime/NodeFactory.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.tuscany.sca.node2; +package org.apache.tuscany.sca.runtime; import java.io.IOException; import java.io.InputStream; @@ -40,12 +40,12 @@ import org.apache.tuscany.sca.deployment.Deployer; import org.apache.tuscany.sca.monitor.ValidationException; import org.apache.tuscany.sca.node.configuration.ContributionConfiguration; import org.apache.tuscany.sca.node.configuration.NodeConfiguration; -import org.apache.tuscany.sca.node2.impl.NodeImpl; 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.runtime.ExtensibleDomainRegistryFactory; import org.apache.tuscany.sca.runtime.RuntimeProperties; +import org.apache.tuscany.sca.runtime.impl.NodeImpl; import org.apache.tuscany.sca.work.WorkScheduler; import org.oasisopen.sca.ServiceRuntimeException; @@ -72,7 +72,7 @@ public class NodeFactory { * @param dependentContributionURLs optional URLs of dependent contributions * @return a Node with installed contributions */ - public static Node newStandaloneNode(String compositeURI, String contributionURL, String... dependentContributionURLs) { + public static Node createStandaloneNode(String compositeURI, String contributionURL, String... dependentContributionURLs) { try { NodeFactory nodeFactory = newInstance(); EndpointRegistry endpointRegistry = new EndpointRegistryImpl(nodeFactory.extensionPointRegistry, null, null); diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/impl/DeployedComposite.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/runtime/impl/DeployedComposite.java index 6e31f283ee..dab3309bfd 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/impl/DeployedComposite.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/runtime/impl/DeployedComposite.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.tuscany.sca.node2.impl; +package org.apache.tuscany.sca.runtime.impl; import java.util.ArrayList; import java.util.HashMap; diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/impl/InstalledContribution.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/runtime/impl/InstalledContribution.java index d847c8d199..4a8e600c76 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/impl/InstalledContribution.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/runtime/impl/InstalledContribution.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.tuscany.sca.node2.impl; +package org.apache.tuscany.sca.runtime.impl; import java.util.ArrayList; import java.util.List; diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/impl/NodeImpl.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/runtime/impl/NodeImpl.java index 15f5e2b18e..2721bf4496 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/node2/impl/NodeImpl.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/runtime/impl/NodeImpl.java @@ -17,11 +17,10 @@ * under the License. */ -package org.apache.tuscany.sca.node2.impl; +package org.apache.tuscany.sca.runtime.impl; import java.io.File; import java.io.Reader; -import java.net.URI; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -33,6 +32,7 @@ import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.common.java.io.IOHelper; import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.Contribution; @@ -42,14 +42,13 @@ 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.ValidationException; -import org.apache.tuscany.sca.node2.Node; -import org.apache.tuscany.sca.node2.NodeFactory; import org.apache.tuscany.sca.runtime.ActivationException; import org.apache.tuscany.sca.runtime.CompositeActivator; import org.apache.tuscany.sca.runtime.EndpointRegistry; -import org.oasisopen.sca.NoSuchDomainException; +import org.apache.tuscany.sca.runtime.Node; +import org.apache.tuscany.sca.runtime.NodeFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.oasisopen.sca.NoSuchServiceException; -import org.oasisopen.sca.client.SCAClientFactory; public class NodeImpl implements Node { @@ -61,6 +60,8 @@ public class NodeImpl implements Node { private ExtensionPointRegistry extensionPointRegistry; private NodeFactory nodeFactory; + private static Map<String, Node> allNodes = new HashMap<String, Node>(); + public NodeImpl(String domainName, Deployer deployer, CompositeActivator compositeActivator, EndpointRegistry endpointRegistry, ExtensionPointRegistry extensionPointRegistry, NodeFactory nodeFactory) { this.domainName = domainName; this.deployer = deployer; @@ -68,6 +69,7 @@ public class NodeImpl implements Node { this.endpointRegistry = endpointRegistry; this.extensionPointRegistry = extensionPointRegistry; this.nodeFactory = nodeFactory; + allNodes.put(domainName, this); } public String installContribution(String contributionURL) throws ContributionReadException, ActivationException, ValidationException { @@ -254,15 +256,25 @@ public class NodeImpl implements Node { if (nodeFactory != null) { nodeFactory.stop(); } + allNodes.remove(this.domainName); } public <T> T getService(Class<T> interfaze, String serviceURI) throws NoSuchServiceException { - try { - return SCAClientFactory.newInstance(URI.create(getDomainName())).getService(interfaze, serviceURI); - } catch (NoSuchDomainException e) { - // shouldn't ever happen as we know this is the domain so it must exist - throw new IllegalStateException(e); + + List<Endpoint> endpoints = endpointRegistry.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); + } } + + return ((RuntimeComponent)endpoints.get(0).getComponent()).getServiceReference(interfaze, serviceName).getService(); } public String getDomainName() { @@ -357,5 +369,9 @@ public class NodeImpl implements Node { public EndpointRegistry getEndpointRegistry() { return endpointRegistry; } + + public static Node nodeExists(String domainName) { + return allNodes.get(domainName); + } } diff --git a/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/DeployerTestCase.java b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/DeployerTestCase.java index 40509337c8..6d4467a895 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/DeployerTestCase.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/DeployerTestCase.java @@ -34,6 +34,8 @@ import org.apache.tuscany.sca.deployment.Deployer; 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.Node; +import org.apache.tuscany.sca.runtime.NodeFactory; import org.junit.Test; import org.oasisopen.sca.NoSuchDomainException; import org.oasisopen.sca.NoSuchServiceException; diff --git a/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/NodeTestCase.java b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/NodeTestCase.java index 6637f05979..2fd1cb7a4e 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/NodeTestCase.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/NodeTestCase.java @@ -25,13 +25,17 @@ import junit.framework.Assert; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.monitor.ValidationException; -import org.apache.tuscany.sca.node2.impl.NodeImpl; import org.apache.tuscany.sca.runtime.ActivationException; +import org.apache.tuscany.sca.runtime.Node; +import org.apache.tuscany.sca.runtime.NodeFactory; +import org.apache.tuscany.sca.runtime.impl.NodeImpl; import org.junit.Ignore; import org.junit.Test; import org.oasisopen.sca.NoSuchDomainException; import org.oasisopen.sca.NoSuchServiceException; +import sample.Helloworld; + public class NodeTestCase { @Test @@ -39,8 +43,30 @@ public class NodeTestCase { Node node = NodeFactory.newInstance().createNode("default"); node.installContribution("helloworld", "src/test/resources/sample-helloworld.jar", null, null, true); -// Helloworld helloworldService = node.getService(Helloworld.class, "HelloworldComponent"); -// Assert.assertEquals("Hello petra", helloworldService.sayHello("petra")); + Helloworld helloworldService = node.getService(Helloworld.class, "HelloworldComponent"); + Assert.assertEquals("Hello petra", helloworldService.sayHello("petra")); + } + + @Test + public void testStopStart() throws NoSuchServiceException, NoSuchDomainException, ContributionReadException, ActivationException, ValidationException { + Node node = NodeFactory.newInstance().createNode("default"); + node.installContribution("helloworld", "src/test/resources/sample-helloworld.jar", null, null, true); + String ci = node.getStartedCompositeURIs("helloworld").get(0); + + Helloworld helloworldService = node.getService(Helloworld.class, "HelloworldComponent"); + Assert.assertEquals("Hello petra", helloworldService.sayHello("petra")); + + node.stop("helloworld", ci); + try { + node.getService(Helloworld.class, "HelloworldComponent"); + Assert.fail(); + } catch (NoSuchServiceException e) { + // expected as there is no deployables + } + + node.start("helloworld", ci); + helloworldService = node.getService(Helloworld.class, "HelloworldComponent"); + Assert.assertEquals("Hello petra", helloworldService.sayHello("petra")); } @Test @@ -50,8 +76,8 @@ public class NodeTestCase { node.installContribution("store", "../../itest/T3558/src/test/resources/sample-store.jar", null, null, true); node.installContribution("store-client", "../../itest/T3558/src/test/resources/sample-store-client.jar", null, null, true); -// Helloworld helloworldService = node.getService(Helloworld.class, "HelloworldComponent"); -// Assert.assertEquals("Hello petra", helloworldService.sayHello("petra")); + Helloworld helloworldService = node.getService(Helloworld.class, "HelloworldComponent"); + Assert.assertEquals("Hello petra", helloworldService.sayHello("petra")); } @Test @@ -59,17 +85,16 @@ public class NodeTestCase { Node node = NodeFactory.newInstance().createNode("default"); node.installContribution("helloworld", "src/test/resources/sample-helloworld-nodeployable.jar", null, null, true); -// SCAClientFactory scaClientFactory = node.getSCAClientFactory(); -// try { -// scaClientFactory.getService(Helloworld.class, "HelloworldComponent"); -// Assert.fail(); -// } catch (NoSuchServiceException e) { -// // expected as there is no deployables -// } + try { + node.getService(Helloworld.class, "HelloworldComponent"); + Assert.fail(); + } catch (NoSuchServiceException e) { + // expected as there is no deployables + } node.start("helloworld", "helloworld.composite"); -// Helloworld helloworldService = scaClientFactory.getService(Helloworld.class, "HelloworldComponent"); -// Assert.assertEquals("Hello petra", helloworldService.sayHello("petra")); + Helloworld helloworldService = node.getService(Helloworld.class, "HelloworldComponent"); + Assert.assertEquals("Hello petra", helloworldService.sayHello("petra")); } @Test @@ -100,7 +125,7 @@ public class NodeTestCase { } @Test - public void testInstallWithMetaData() throws ContributionReadException, ActivationException, ValidationException { + public void testInstallWithMetaData() throws ContributionReadException, ActivationException, ValidationException, NoSuchServiceException { Node node = NodeFactory.newInstance().createNode("default"); ((NodeImpl)node).installContribution("helloworld", "src/test/resources/sample-helloworld-nodeployable.jar", "src/test/resources/sca-contribution-generated.xml", null, true); @@ -108,8 +133,8 @@ public class NodeTestCase { Assert.assertEquals(1, dcs.size()); Assert.assertEquals("helloworld.composite", dcs.get(0)); -// Helloworld helloworldService = scaClientFactory.getService(Helloworld.class, "HelloworldComponent"); -// Assert.assertEquals("Hello petra", helloworldService.sayHello("petra")); + Helloworld helloworldService = node.getService(Helloworld.class, "HelloworldComponent"); + Assert.assertEquals("Hello petra", helloworldService.sayHello("petra")); } @Test @@ -121,7 +146,7 @@ public class NodeTestCase { @Test public void testStaticCreate() { - Node node = NodeFactory.newStandaloneNode("helloworld.composite", "src/test/resources/sample-helloworld.jar"); + Node node = NodeFactory.createStandaloneNode("helloworld.composite", "src/test/resources/sample-helloworld.jar"); List<String> cs = node.getInstalledContributionURIs(); Assert.assertEquals(1, cs.size()); List<String> dcs = node.getStartedCompositeURIs(cs.get(0)); @@ -131,7 +156,7 @@ public class NodeTestCase { @Test public void testStaticCreateWithNullComposite() { - Node node = NodeFactory.newStandaloneNode(null, "src/test/resources/sample-helloworld.jar"); + Node node = NodeFactory.createStandaloneNode(null, "src/test/resources/sample-helloworld.jar"); List<String> cs = node.getInstalledContributionURIs(); Assert.assertEquals(1, cs.size()); List<String> dcs = node.getStartedCompositeURIs(cs.get(0)); diff --git a/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/NodeXMLTestCase.java b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/NodeXMLTestCase.java index 5e265a0c8a..694b0b6f6a 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/NodeXMLTestCase.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/node2/NodeXMLTestCase.java @@ -25,6 +25,8 @@ import junit.framework.Assert; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.monitor.ValidationException; import org.apache.tuscany.sca.runtime.ActivationException; +import org.apache.tuscany.sca.runtime.Node; +import org.apache.tuscany.sca.runtime.NodeFactory; import org.junit.Test; public class NodeXMLTestCase { diff --git a/sca-java-2.x/trunk/modules/domain-node/src/test/resources/itest-nodes-helloworld-client-2.0-SNAPSHOT.jar b/sca-java-2.x/trunk/modules/domain-node/src/test/resources/itest-nodes-helloworld-client-2.0-SNAPSHOT.jar Binary files differindex 3e9ae79a41..7f6073ce7f 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/test/resources/itest-nodes-helloworld-client-2.0-SNAPSHOT.jar +++ b/sca-java-2.x/trunk/modules/domain-node/src/test/resources/itest-nodes-helloworld-client-2.0-SNAPSHOT.jar diff --git a/sca-java-2.x/trunk/modules/domain-node/src/test/resources/itest-nodes-helloworld-service-2.0-SNAPSHOT.jar b/sca-java-2.x/trunk/modules/domain-node/src/test/resources/itest-nodes-helloworld-service-2.0-SNAPSHOT.jar Binary files differindex 40333cab75..2306ce4d1a 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/test/resources/itest-nodes-helloworld-service-2.0-SNAPSHOT.jar +++ b/sca-java-2.x/trunk/modules/domain-node/src/test/resources/itest-nodes-helloworld-service-2.0-SNAPSHOT.jar diff --git a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java index ba4ba8a63f..d45e95e863 100644 --- a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java +++ b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java @@ -46,13 +46,13 @@ 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.monitor.ValidationException;
-import org.apache.tuscany.sca.node2.Node;
-import org.apache.tuscany.sca.node2.NodeFactory;
-import org.apache.tuscany.sca.node2.impl.NodeImpl;
import org.apache.tuscany.sca.runtime.ActivationException;
import org.apache.tuscany.sca.runtime.EndpointRegistry;
+import org.apache.tuscany.sca.runtime.Node;
+import org.apache.tuscany.sca.runtime.NodeFactory;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.apache.tuscany.sca.runtime.Version;
+import org.apache.tuscany.sca.runtime.impl.NodeImpl;
import org.apache.tuscany.sca.shell.jline.JLine;
/**
@@ -405,7 +405,7 @@ public class Shell { boolean start(String nodeName, String compositeURI, String contributionURL, String... dependentContributionURLs)
throws ActivationException, ValidationException {
- Node node = NodeFactory.newStandaloneNode(compositeURI, contributionURL, dependentContributionURLs);
+ Node node = NodeFactory.createStandaloneNode(compositeURI, contributionURL, dependentContributionURLs);
standaloneNodes.put(nodeName, node);
return true;
}
diff --git a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/ServiceCompletor.java b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/ServiceCompletor.java index 69b8fbd033..d23e04b331 100644 --- a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/ServiceCompletor.java +++ b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/ServiceCompletor.java @@ -25,8 +25,8 @@ import java.util.List; import jline.SimpleCompletor; import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.node2.impl.NodeImpl; import org.apache.tuscany.sca.runtime.EndpointRegistry; +import org.apache.tuscany.sca.runtime.impl.NodeImpl; import org.apache.tuscany.sca.shell.Shell; /** diff --git a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/ServiceOperationCompletor.java b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/ServiceOperationCompletor.java index d4e1fc55e4..82e102a904 100644 --- a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/ServiceOperationCompletor.java +++ b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/ServiceOperationCompletor.java @@ -27,9 +27,9 @@ import java.util.List; import jline.SimpleCompletor; import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.node2.impl.NodeImpl; import org.apache.tuscany.sca.runtime.EndpointRegistry; import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.impl.NodeImpl; import org.apache.tuscany.sca.shell.Shell; /** |