From 98802478a84a42af4a4bf7c28a815ade993eab6a Mon Sep 17 00:00:00 2001 From: antelder Date: Thu, 28 Jan 2010 18:40:43 +0000 Subject: 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 --- .../core/runtime/DefaultDomainRegistryFactory.java | 6 ++--- .../client/HazelcastClientEndpointRegistry.java | 2 +- ...org.apache.tuscany.sca.runtime.EndpointRegistry | 2 +- .../tuscany/sca/endpoint/hazelcast/ConfigURI.java | 8 +++---- .../sca/client/rmi/SCAClientFactoryImpl.java | 26 +++++++++++++++++++-- .../sca/client/rmi/SCAClientProxyHandler.java | 27 +++++++++++----------- .../tuscany/sca/client/rmi/ClientTestCase.java | 2 +- 7 files changed, 48 insertions(+), 25 deletions(-) (limited to 'sca-java-2.x/trunk/modules') 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 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 getService(Class 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); -- cgit v1.2.3