summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-11-27 08:54:19 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-11-27 08:54:19 +0000
commit4ba50f2c380e454217fd9ab7b5de78997a1f7470 (patch)
treee1eb3a12392ae336970dbb5123717ded3127aad8 /sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java
parent2b2c65af50cee1c708cb77f815dd82dee4aac820 (diff)
Update rmi client to use local nodes for local domains
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@884788 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java')
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientFactoryImpl.java78
1 files changed, 55 insertions, 23 deletions
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 932f43c4c4..e64b2c8917 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
@@ -22,14 +22,18 @@ package org.apache.tuscany.sca.client.rmi;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.net.URI;
+import java.util.List;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFinder;
import org.apache.tuscany.sca.runtime.DomainRegistryFactory;
import org.apache.tuscany.sca.runtime.EndpointRegistry;
import org.oasisopen.sca.NoSuchDomainException;
import org.oasisopen.sca.NoSuchServiceException;
+import org.oasisopen.sca.ServiceUnavailableException;
import org.oasisopen.sca.client.SCAClientFactory;
public class SCAClientFactoryImpl extends SCAClientFactory {
@@ -40,39 +44,46 @@ public class SCAClientFactoryImpl extends SCAClientFactory {
public SCAClientFactoryImpl(URI domainURI) {
super(domainURI);
- this.extensionsRegistry = new DefaultExtensionPointRegistry();
- UtilityExtensionPoint utilities = extensionsRegistry.getExtensionPoint(UtilityExtensionPoint.class);
- DomainRegistryFactory domainRegistryFactory = utilities.getUtility(DomainRegistryFactory.class);
- this.endpointRegistry = domainRegistryFactory.getEndpointRegistry(getDomainURI().toString(), getDomainName());
+ if (!"vm".equals(domainURI.getScheme())) {
+ this.extensionsRegistry = new DefaultExtensionPointRegistry();
+ UtilityExtensionPoint utilities = extensionsRegistry.getExtensionPoint(UtilityExtensionPoint.class);
+ DomainRegistryFactory domainRegistryFactory = utilities.getUtility(DomainRegistryFactory.class);
+ this.endpointRegistry = domainRegistryFactory.getEndpointRegistry(getDomainURI().toString(), getDomainName());
- try {
- // TODO: wait a mo for the endpoint registry to replicate
- Thread.sleep(5000);
- } catch (InterruptedException e) {
+ try {
+ // TODO: wait a mo for the endpoint registry to replicate
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ }
}
}
@Override
@SuppressWarnings("unchecked")
public <T> T getService(Class<T> serviceInterface, String serviceName) throws NoSuchServiceException, NoSuchDomainException {
- InvocationHandler handler = new SCAClientProxyHandler(serviceName, extensionsRegistry, endpointRegistry);
- return (T)Proxy.newProxyInstance(serviceInterface.getClassLoader(), new Class[] {serviceInterface}, handler);
+ if ("vm".equals(getDomainURI().getScheme())) {
+ return getLocalService(serviceInterface, serviceName);
+ } else {
+ InvocationHandler handler = new SCAClientProxyHandler(serviceName, extensionsRegistry, endpointRegistry);
+ return (T)Proxy.newProxyInstance(serviceInterface.getClassLoader(), new Class[] {serviceInterface}, handler);
+ }
}
private String getDomainName() {
- String uri = getDomainURI().toString();
- int i = uri.indexOf(":");
- if (i > -1 && uri.charAt(i+1) != '/') {
- uri = uri.replaceFirst(":", ":/");
- }
- if (i > -1 && uri.charAt(i+2) != '/') {
- uri = uri.replaceFirst(":/", "://");
- }
- if (i < 0) {
- return uri;
- } else {
- return URI.create(uri).getHost();
- }
+// String uri = getDomainURI().toString();
+// int i = uri.indexOf(":");
+// if (i > -1 && uri.charAt(i+1) != '/') {
+// uri = uri.replaceFirst(":", ":/");
+// }
+// if (i > -1 && uri.charAt(i+2) != '/') {
+// uri = uri.replaceFirst(":/", "://");
+// }
+// if (i < 0) {
+// return uri;
+// } else {
+// return URI.create(uri).getHost();
+// }
+ return getDomainURI().toString();
}
public void stop() {
@@ -86,4 +97,25 @@ public class SCAClientFactoryImpl extends SCAClientFactory {
public ExtensionPointRegistry getExtensionsRegistry() {
return extensionsRegistry;
}
+
+ public <T> T getLocalService(Class<T> serviceInterface, String serviceName) throws NoSuchServiceException, NoSuchDomainException {
+ URI domainURI = getDomainURI();
+ if (domainURI == null) {
+ domainURI = URI.create(Node.DEFAULT_DOMAIN_URI);
+ }
+ List<Node> nodes = NodeFinder.getNodes(domainURI);
+ if (nodes == null || nodes.size() < 1) {
+ throw new NoSuchDomainException(domainURI.toString());
+ }
+
+ for (Node n : nodes) {
+ try {
+ return n.getService(serviceInterface, serviceName);
+ } catch(ServiceUnavailableException e) {
+ // Ingore and continue
+ }
+ }
+
+ throw new NoSuchServiceException(serviceName);
+ }
}