diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca')
-rw-r--r-- | sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientFactoryImpl.java | 78 |
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);
+ }
}
|