summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/sca-client-impl
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-01-20 16:42:59 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-01-20 16:42:59 +0000
commit630599c9de5bce09c7fb1f1b657ae36164c5cc40 (patch)
treecac9a8b81dd1a10644128a0725183bc79b7d59fa /sca-java-2.x/trunk/modules/sca-client-impl
parent1006c4802c6dadbcc4ffc874044b8a8e7bf0ec2e (diff)
Start of making the Tuscany sca client impl work for both local or remote nodes and to be generic for any binding. Work in progress, only local invocations work presently
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@901270 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/sca-client-impl')
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-impl/META-INF/MANIFEST.MF5
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java65
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientProxyHandler.java76
3 files changed, 131 insertions, 15 deletions
diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/sca-client-impl/META-INF/MANIFEST.MF
index ddfe8a0276..ae6fcb3ce3 100644
--- a/sca-java-2.x/trunk/modules/sca-client-impl/META-INF/MANIFEST.MF
+++ b/sca-java-2.x/trunk/modules/sca-client-impl/META-INF/MANIFEST.MF
@@ -6,8 +6,11 @@ Bundle-Version: 2.0.0
Bundle-ManifestVersion: 2
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
Bundle-Description: Apache Tuscany SCA Client Impl
-Import-Package: org.apache.tuscany.sca.core;version="2.0.0",
+Import-Package: org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.core;version="2.0.0",
org.apache.tuscany.sca.node;version="2.0.0",
+ org.apache.tuscany.sca.node.impl;version="2.0.0",
+ org.apache.tuscany.sca.runtime;version="2.0.0",
org.oasisopen.sca;version="2.0.0",
org.oasisopen.sca.client;version="2.0.0"
Bundle-SymbolicName: org.apache.tuscany.sca.client.impl
diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java
index 7afc6bbe07..ef5dabeb67 100644
--- a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java
+++ b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java
@@ -19,14 +19,22 @@
package org.apache.tuscany.sca.client.impl;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
import java.net.URI;
import java.util.List;
+import org.apache.tuscany.sca.assembly.Endpoint;
+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.node.NodeFactory;
+import org.apache.tuscany.sca.node.impl.NodeFactoryImpl;
+import org.apache.tuscany.sca.node.impl.NodeImpl;
+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;
import org.oasisopen.sca.client.SCAClientFactoryFinder;
@@ -35,30 +43,59 @@ public class SCAClientFactoryImpl extends SCAClientFactory {
public static void setSCAClientFactoryFinder(SCAClientFactoryFinder factoryFinder) {
SCAClientFactory.factoryFinder = factoryFinder;
}
+
+ private ExtensionPointRegistry extensionsRegistry;
+ private EndpointRegistry endpointRegistry;
+ private NodeFactoryImpl nodeFactory;
public SCAClientFactoryImpl(URI domainURI) throws NoSuchDomainException {
super(domainURI);
+
+ this.nodeFactory = (NodeFactoryImpl)NodeFactory.getInstance();
+ this.extensionsRegistry = nodeFactory.getExtensionPoints();
+ UtilityExtensionPoint utilities = extensionsRegistry.getExtensionPoint(UtilityExtensionPoint.class);
+ DomainRegistryFactory domainRegistryFactory = utilities.getUtility(DomainRegistryFactory.class);
+ this.endpointRegistry = domainRegistryFactory.getEndpointRegistry(null, getDomainURI().toString()); // TODO: shouldnt use null for reg uri
+ // TODO: if there is not an existing endpoint registry for the domain URI the
+ // this should create an endpoint registry client for the remote domain (eg hazelcast native client)
+ // for now just throw an exception
+ if (endpointRegistry == null) {
+ throw new NoSuchDomainException(domainURI.toString());
+ }
}
@Override
public <T> T getService(Class<T> serviceInterface, String serviceName) throws NoSuchServiceException, NoSuchDomainException {
- URI domainURI = getDomainURI();
- if (domainURI == null) {
- domainURI = URI.create(Node.DEFAULT_DOMAIN_URI);
+
+ List<Endpoint> eps = endpointRegistry.findEndpoint(serviceName);
+ if (eps == null || eps.size() < 1) {
+ throw new NoSuchServiceException(serviceName);
}
- List<Node> nodes = NodeFinder.getNodes(domainURI);
- if (nodes == null || nodes.size() < 1) {
- throw new NoSuchDomainException(domainURI.toString());
+ Endpoint endpoint = eps.get(0); // TODO: what should be done with multiple endpoints?
+
+ Node localNode = findLocalNode(endpoint);
+ if (localNode != null) {
+ return localNode.getService(serviceInterface, serviceName);
}
- for (Node n : nodes) {
- try {
- return n.getService(serviceInterface, serviceName);
- } catch(ServiceUnavailableException e) {
- // Ingore and continue
+ InvocationHandler handler = new SCAClientProxyHandler(serviceName, extensionsRegistry, endpointRegistry);
+ return (T)Proxy.newProxyInstance(serviceInterface.getClassLoader(), new Class[] {serviceInterface}, handler);
+ }
+
+ private Node findLocalNode(Endpoint endpoint) {
+ for (Node node : nodeFactory.getNodes().values()) {
+ if (((NodeImpl)node).getServiceEndpoints().contains(endpoint)) {
+ return node;
}
}
+ return null;
+ }
- throw new NoSuchServiceException(serviceName);
+ private String getDomainName() {
+ // TODO: parse to extract just the domain name from the uri
+ if (getDomainURI().getHost() != null) {
+ return getDomainURI().getHost();
+ }
+ return getDomainURI().toString();
}
}
diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientProxyHandler.java b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientProxyHandler.java
new file mode 100644
index 0000000000..c5913070e8
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientProxyHandler.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.client.impl;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
+import org.oasisopen.sca.NoSuchServiceException;
+
+/**
+ * TODO: What this wants is a way to create a generic invoker for an arbitrary binding
+ * that could mean extending the BindingProvider API to include something like a
+ * createClient method which creates an Invoker for an Endpoint
+ */
+public class SCAClientProxyHandler implements InvocationHandler {
+
+ protected EndpointRegistry endpointRegistry;
+ protected EndpointReference endpointReference;
+ protected String serviceName;
+
+ public SCAClientProxyHandler(String serviceName, ExtensionPointRegistry extensionsRegistry, EndpointRegistry endpointRegistry) {
+ this.endpointRegistry = endpointRegistry;
+ this.serviceName = serviceName;
+
+// 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 {
+
+ List<Endpoint> endpoints = endpointRegistry.findEndpoint(endpointReference);
+ if (endpoints.size() <1 ) {
+ throw new NoSuchServiceException(serviceName);
+ }
+
+ String uri = endpoints.get(0).getBinding().getURI();
+// RMIBindingInvoker invoker = new RMIBindingInvoker(rmiHost, uri, method);
+//
+// return invoker.invokeTarget(args);
+ return null;
+ }
+
+}