summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-01-28 18:40:43 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-01-28 18:40:43 +0000
commit98802478a84a42af4a4bf7c28a815ade993eab6a (patch)
tree9acec14c9042bb53f0c2e1a16f485bfb2dbc474e
parent492f58500ba6d94838b8785860574e7665effa4d (diff)
Change the tuscanyClient scheme to pbe all lower case so it works with the toLowerCase in the DefaultEndpointRegistryFactory, and move all the remote code in the scaclient to happen at invocation time. This now works for multiple local and remote nodes in one or separate JVMs
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@904206 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--sca-java-2.x/trunk/distribution/tomcat/testing/helloworld-scaclient-javase/src/main/java/testing/HelloworldClient.java2
-rw-r--r--sca-java-2.x/trunk/itest/scaclient-api-rmi/src/test/java/test/scaclient/SCAClientTestCase.java9
-rw-r--r--sca-java-2.x/trunk/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java10
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/DefaultDomainRegistryFactory.java6
-rw-r--r--sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/client/HazelcastClientEndpointRegistry.java2
-rw-r--r--sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry2
-rw-r--r--sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/ConfigURI.java8
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientFactoryImpl.java26
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientProxyHandler.java27
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-rmi/src/test/java/org/apache/tuscany/sca/client/rmi/ClientTestCase.java2
10 files changed, 68 insertions, 26 deletions
diff --git a/sca-java-2.x/trunk/distribution/tomcat/testing/helloworld-scaclient-javase/src/main/java/testing/HelloworldClient.java b/sca-java-2.x/trunk/distribution/tomcat/testing/helloworld-scaclient-javase/src/main/java/testing/HelloworldClient.java
index 8d456efc30..b36fe418a4 100644
--- a/sca-java-2.x/trunk/distribution/tomcat/testing/helloworld-scaclient-javase/src/main/java/testing/HelloworldClient.java
+++ b/sca-java-2.x/trunk/distribution/tomcat/testing/helloworld-scaclient-javase/src/main/java/testing/HelloworldClient.java
@@ -33,7 +33,7 @@ public class HelloworldClient {
if (args.length > 0) {
domainURI = URI.create(args[0]);
} else {
- domainURI = URI.create("tuscany:default");
+ domainURI = URI.create("tuscany:default?remotes=192.168.1.73:14820");
}
SCAClientFactory factory = SCAClientFactory.newInstance(domainURI);
diff --git a/sca-java-2.x/trunk/itest/scaclient-api-rmi/src/test/java/test/scaclient/SCAClientTestCase.java b/sca-java-2.x/trunk/itest/scaclient-api-rmi/src/test/java/test/scaclient/SCAClientTestCase.java
index 072c275c8b..35e5e28194 100644
--- a/sca-java-2.x/trunk/itest/scaclient-api-rmi/src/test/java/test/scaclient/SCAClientTestCase.java
+++ b/sca-java-2.x/trunk/itest/scaclient-api-rmi/src/test/java/test/scaclient/SCAClientTestCase.java
@@ -61,6 +61,15 @@ public class SCAClientTestCase extends TestCase {
@Test
public void testExplicitRemote() throws Exception {
+ node = NodeFactory.newInstance().createNode(URI.create("tuscany:myFooDomain?listen=127.0.0.1:14821"), new String[] {"target/classes"});
+ node.start();
+
+ HelloworldService service = SCAClientFactory.newInstance(URI.create("tuscany:myFooDomain?remotes=127.0.0.1:14821")).getService(HelloworldService.class, "HelloworldComponent");
+ assertEquals("Hello petra", service.sayHello("petra"));
+ }
+
+ @Test
+ public void testExplicitRemote2() throws Exception {
node = NodeFactory.getInstance().createNode(URI.create("tuscany:myFooDomain?listen=127.0.0.1:14821"), new String[] {"target/classes"});
node.start();
diff --git a/sca-java-2.x/trunk/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java b/sca-java-2.x/trunk/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java
index 5e35fa674c..891581ea36 100644
--- a/sca-java-2.x/trunk/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java
+++ b/sca-java-2.x/trunk/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java
@@ -27,6 +27,7 @@ import junit.framework.TestCase;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.Ignore;
import org.junit.Test;
import org.oasisopen.sca.client.SCAClientFactory;
@@ -58,6 +59,15 @@ public class SCAClientTestCase extends TestCase {
assertEquals("Hello petra", service.sayHello("petra"));
}
+// @Test @Ignore
+// public void testHTTPURI() throws Exception {
+// node = NodeFactory.getInstance().createNode(URI.create("http://defaultDomain"), new String[] {"target/classes"});
+// node.start();
+//
+// HelloworldService service = SCAClientFactory.newInstance(URI.create("http://defaultDomain")).getService(HelloworldService.class, "HelloworldComponent");
+// assertEquals("Hello petra", service.sayHello("petra"));
+// }
+
@Override
protected void tearDown() throws Exception {
node.stop();
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/DefaultDomainRegistryFactory.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/DefaultDomainRegistryFactory.java
index 8bd5df8386..784eca90ab 100644
--- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/DefaultDomainRegistryFactory.java
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/DefaultDomainRegistryFactory.java
@@ -76,7 +76,7 @@ public class DefaultDomainRegistryFactory implements DomainRegistryFactory, Life
}
String key;
- if (endpointRegistryURI.startsWith("tuscany:") || endpointRegistryURI.startsWith("tuscanyClient:")){
+ if (endpointRegistryURI.startsWith("tuscany:") || endpointRegistryURI.startsWith("tuscanyclient:")){
key = "tuscany:," + domainURI;
} else {
key = endpointRegistryURI + "," + domainURI;
@@ -98,7 +98,7 @@ public class DefaultDomainRegistryFactory implements DomainRegistryFactory, Life
return endpointRegistry;
}
- String scheme = "tuscanyClient:".equals(endpointRegistryURI) ? "tuscanyClient" : URI.create(endpointRegistryURI).getScheme();
+ String scheme = "tuscanyclient:".equals(endpointRegistryURI) ? "tuscanyClient" : URI.create(endpointRegistryURI).getScheme();
if (scheme != null) {
scheme = scheme.toLowerCase();
} else {
@@ -134,7 +134,7 @@ public class DefaultDomainRegistryFactory implements DomainRegistryFactory, Life
for (EndpointListener listener : listeners) {
endpointRegistry.addListener(listener);
}
- if (!"tuscanyClient:".equals(endpointRegistryURI)) {
+ if (!"tuscanyclient:".equals(endpointRegistryURI)) {
endpointRegistries.put(key, endpointRegistry);
}
return endpointRegistry;
diff --git a/sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/client/HazelcastClientEndpointRegistry.java b/sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/client/HazelcastClientEndpointRegistry.java
index 5ba660171e..3819f9b3db 100644
--- a/sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/client/HazelcastClientEndpointRegistry.java
+++ b/sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/client/HazelcastClientEndpointRegistry.java
@@ -37,7 +37,7 @@ public class HazelcastClientEndpointRegistry extends HazelcastEndpointRegistry {
Map<String, String> attributes,
String domainRegistryURI,
String domainURI) {
- super(registry, attributes, domainURI, domainRegistryURI);
+ super(registry, attributes, domainRegistryURI, domainURI);
}
@Override
diff --git a/sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry b/sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry
index ca34978fe8..5f8e2060f9 100644
--- a/sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry
+++ b/sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry
@@ -14,5 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-org.apache.tuscany.sca.endpoint.hazelcast.client.HazelcastClientEndpointRegistry;ranking=150,scheme=tuscanyClient
+org.apache.tuscany.sca.endpoint.hazelcast.client.HazelcastClientEndpointRegistry;ranking=150,scheme=tuscanyclient
diff --git a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/ConfigURI.java b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/ConfigURI.java
index 066ff187db..0eee731249 100644
--- a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/ConfigURI.java
+++ b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/ConfigURI.java
@@ -59,8 +59,8 @@ public class ConfigURI {
}
private void parseURI(String uri) {
- if (uri.startsWith("tuscanyClient:")) {
- uri = uri.replace("tuscanyClient:", "tuscany:");
+ if (uri.startsWith("tuscanyclient:")) {
+ uri = uri.replace("tuscanyclient:", "tuscany:");
}
if (!uri.startsWith("tuscany:")) {
@@ -69,10 +69,10 @@ public class ConfigURI {
// make it a URI so java.net.URI can be used to parse it
int i = uri.indexOf(":");
- if (uri.charAt("tuscany:".length()+1) != '/') {
+ if (uri.charAt("tuscany:".length()) != '/') {
uri = uri.replaceFirst(":", ":/");
}
- if (uri.charAt("tuscany:".length()+2) != '/') {
+ if (uri.charAt("tuscany:".length()+1) != '/') {
uri = uri.replaceFirst(":/", "://");
}
URI configURI = URI.create(uri);
diff --git a/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientFactoryImpl.java b/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientFactoryImpl.java
index cde91739c0..f949763e9b 100644
--- a/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientFactoryImpl.java
+++ b/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientFactoryImpl.java
@@ -56,10 +56,32 @@ public class SCAClientFactoryImpl extends SCAClientFactory {
if (extensionsRegistry != null) {
UtilityExtensionPoint utilities = extensionsRegistry.getExtensionPoint(UtilityExtensionPoint.class);
DomainRegistryFactory domainRegistryFactory = utilities.getUtility(DomainRegistryFactory.class);
- this.endpointRegistry = domainRegistryFactory.getEndpointRegistry("tuscanyClient:", getDomainURI().toString()); // TODO: shouldnt use null for reg uri
+ this.endpointRegistry = domainRegistryFactory.getEndpointRegistry(getRegistryURI(), getDomainName());
}
}
+ private String getRegistryURI() {
+ String uri = getDomainURI().toString();
+ if (uri.startsWith("tuscany:")) {
+ uri = uri.replace("tuscany:", "tuscanyclient:");
+ }
+ return uri;
+ }
+
+ private String getDomainName() {
+ if (getDomainURI().getHost() != null) {
+ return getDomainURI().getHost();
+ }
+ String uri = getDomainURI().toString();
+ if (!uri.startsWith("tuscany://")) {
+ if (uri.startsWith("tuscany:")) {
+ uri = uri.replace("tuscany:", "tuscany://");
+ return URI.create(uri).getHost();
+ }
+ }
+ return uri;
+ }
+
@Override
public <T> T getService(Class<T> serviceInterface, String serviceName) throws NoSuchServiceException, NoSuchDomainException {
@@ -78,7 +100,7 @@ public class SCAClientFactoryImpl extends SCAClientFactory {
String uri = getDomainURI().toString();
if (uri.startsWith("tuscany:")) {
- uri = uri.replace("tuscany:", "tuscanyClient:");
+ uri = uri.replace("tuscany:", "tuscanyclient://");
}
InvocationHandler handler = new SCAClientProxyHandler(nodeFactory, uri, serviceName);
return (T)Proxy.newProxyInstance(serviceInterface.getClassLoader(), new Class[] {serviceInterface}, handler);
diff --git a/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientProxyHandler.java b/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientProxyHandler.java
index 6d182c61a7..b65f311da2 100644
--- a/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientProxyHandler.java
+++ b/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientProxyHandler.java
@@ -55,25 +55,26 @@ public class SCAClientProxyHandler implements InvocationHandler {
this.nodeFactory = nodeFactory;
this.domainURI = domainURI;
this.serviceName = serviceName;
- this.extensionsRegistry = nodeFactory.getExtensionPoints();
- RMIHostExtensionPoint rmiHosts = extensionsRegistry.getExtensionPoint(RMIHostExtensionPoint.class);
- this.rmiHost = new ExtensibleRMIHost(rmiHosts);
-
- FactoryExtensionPoint factories = extensionsRegistry.getExtensionPoint(FactoryExtensionPoint.class);
- AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class);
-
- this.endpointReference = assemblyFactory.createEndpointReference();
- endpointReference.setReference(assemblyFactory.createComponentReference());
- Endpoint targetEndpoint = assemblyFactory.createEndpoint();
- targetEndpoint.setURI(serviceName);
- endpointReference.setTargetEndpoint(targetEndpoint);
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Node node = null;
try {
- node = NodeFactory.newInstance().createNode(URI.create(domainURI)).start();
+ nodeFactory = (NodeFactoryImpl)NodeFactory.newInstance();
+ node = nodeFactory.createNode(URI.create(domainURI)).start();
+ this.extensionsRegistry = nodeFactory.getExtensionPoints();
+ RMIHostExtensionPoint rmiHosts = extensionsRegistry.getExtensionPoint(RMIHostExtensionPoint.class);
+ this.rmiHost = new ExtensibleRMIHost(rmiHosts);
+
+ FactoryExtensionPoint factories = extensionsRegistry.getExtensionPoint(FactoryExtensionPoint.class);
+ AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class);
+
+ this.endpointReference = assemblyFactory.createEndpointReference();
+ endpointReference.setReference(assemblyFactory.createComponentReference());
+ Endpoint targetEndpoint = assemblyFactory.createEndpoint();
+ targetEndpoint.setURI(serviceName);
+ endpointReference.setTargetEndpoint(targetEndpoint);
UtilityExtensionPoint utilities = extensionsRegistry.getExtensionPoint(UtilityExtensionPoint.class);
DomainRegistryFactory domainRegistryFactory = utilities.getUtility(DomainRegistryFactory.class);
this.endpointRegistry = domainRegistryFactory.getEndpointRegistry(null, domainURI);
diff --git a/sca-java-2.x/trunk/modules/sca-client-rmi/src/test/java/org/apache/tuscany/sca/client/rmi/ClientTestCase.java b/sca-java-2.x/trunk/modules/sca-client-rmi/src/test/java/org/apache/tuscany/sca/client/rmi/ClientTestCase.java
index 8ca5e0748b..dd30719869 100644
--- a/sca-java-2.x/trunk/modules/sca-client-rmi/src/test/java/org/apache/tuscany/sca/client/rmi/ClientTestCase.java
+++ b/sca-java-2.x/trunk/modules/sca-client-rmi/src/test/java/org/apache/tuscany/sca/client/rmi/ClientTestCase.java
@@ -40,7 +40,7 @@ public class ClientTestCase {
Node node = NodeFactory.newInstance().createNode(URI.create("tuscany:foo?listen=127.0.0.1:14828"), new String[]{"../../samples/calculator/target/sample-calculator.jar"});
node.start();
- SCAClientFactoryImpl cf = new SCAClientFactoryImpl(URI.create("tuscanyClient:foo?remotes=127.0.0.1:14828"));
+ SCAClientFactoryImpl cf = new SCAClientFactoryImpl(URI.create("tuscanyclient:foo?remotes=127.0.0.1:14828"));
CalculatorService service = cf.getService(CalculatorService.class, "CalculatorServiceComponent");
assertEquals(3, service.add(1, 2), 0);