Hi Raymond, it sounds like we're thinking along similar lines, I've already a implementation.client impl which i've been experimenting with trying using Nodes and a dynamically generated composite (though i've not had it working well yet). That does though have far more than the client needs so theres also the simpler approach thats currently committed. Its also just an implementation detail, what i'd like to do first now that there is at least something working is to get some more thorough tests of the various scenarios to help get a common understanding of how to do things and what does or doesn't work with the current runtime.
...ant On Wed, Jan 20, 2010 at 5:34 PM, Raymond Feng <[email protected]> wrote: > Hi, > > I'm interested in the design of SCAClient, especially for the remote client. > Can you give us a quick overview? > > I have been working on the OSGi remote services using SCA. I believe there > are common requirements and we can share some thoughts. > > Here is what I have in mind how the remote SCA client could work (in a > similar way as OSGi remote services work): > > 1) An SCA client could be modeled as a special Node with a deployment > composite that contains the an endpoint reference to the remote service in > the SCA domain. > > 2) The SCA client connects to the domain registry to receive endpoint/policy > description from the SCA domain. > > 3) The deployment composite is dynamically generated at the client side. For > example: > > <composite ...> > <component name="..."> > <implementation.client ...> > <reference target="..." ...> <!-- Will be bound to the remote SCA > service endpoint description --> > </reference> > </component> > </composite> > > 4) We start the client Node and use the Node API to get the service proxy. > > One concern that I have is that the client runtime might become too heavy to > support all the bindings and policies. > > Thanks, > Raymond > > -------------------------------------------------- > From: <[email protected]> > Sent: Wednesday, January 20, 2010 8:43 AM > To: <[email protected]> > Subject: svn commit: r901270 - in /tuscany/sca-java-2.x/trunk: > itest/scaclient-api-jse-osgi/src/test/java/test/scaclient/ > itest/scaclient-api-osgi/src/test/java/test/scaclient/ > itest/scaclient-api/src/test/java/test/scaclient/ > modules/core-spi/src/main/java/org... > >> Author: antelder >> Date: Wed Jan 20 16:42:59 2010 >> New Revision: 901270 >> >> URL: http://svn.apache.org/viewvc?rev=901270&view=rev >> Log: >> 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 >> >> Added: >> >> >> tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientProxyHandler.java >> Modified: >> >> >> tuscany/sca-java-2.x/trunk/itest/scaclient-api-jse-osgi/src/test/java/test/scaclient/SCAClientTestCase.java >> >> >> tuscany/sca-java-2.x/trunk/itest/scaclient-api-osgi/src/test/java/test/scaclient/SCAClientTestCase.java >> >> >> tuscany/sca-java-2.x/trunk/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java >> >> >> tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java >> >> >> tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointRegistryImpl.java >> >> >> tuscany/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java >> >> >> tuscany/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java >> tuscany/sca-java-2.x/trunk/modules/sca-client-impl/META-INF/MANIFEST.MF >> >> >> tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java >> >> Modified: >> tuscany/sca-java-2.x/trunk/itest/scaclient-api-jse-osgi/src/test/java/test/scaclient/SCAClientTestCase.java >> URL: >> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/scaclient-api-jse-osgi/src/test/java/test/scaclient/SCAClientTestCase.java?rev=901270&r1=901269&r2=901270&view=diff >> >> ============================================================================== >> --- >> tuscany/sca-java-2.x/trunk/itest/scaclient-api-jse-osgi/src/test/java/test/scaclient/SCAClientTestCase.java >> (original) >> +++ >> tuscany/sca-java-2.x/trunk/itest/scaclient-api-jse-osgi/src/test/java/test/scaclient/SCAClientTestCase.java >> Wed Jan 20 16:42:59 2010 >> @@ -19,6 +19,8 @@ >> >> package test.scaclient; >> >> +import java.net.URI; >> + >> import itest.HelloworldService; >> import junit.framework.TestCase; >> >> @@ -49,7 +51,7 @@ >> // At the moment the SCAClientFactory assumes that only one domain >> is active >> // in a JVM. So we pass in null for the domain name and get what >> we're given >> HelloworldService service = >> - SCAClientFactory.newInstance(null).getService(HelloworldService.class, >> "HelloworldComponent"); >> + >> SCAClientFactory.newInstance(URI.create("http://tuscany.apache.org/sca/1.1/domains/default")).getService(HelloworldService.class, >> "HelloworldComponent"); >> assertEquals("Hello petra", service.sayHello("petra")); >> } >> >> >> Modified: >> tuscany/sca-java-2.x/trunk/itest/scaclient-api-osgi/src/test/java/test/scaclient/SCAClientTestCase.java >> URL: >> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/scaclient-api-osgi/src/test/java/test/scaclient/SCAClientTestCase.java?rev=901270&r1=901269&r2=901270&view=diff >> >> ============================================================================== >> --- >> tuscany/sca-java-2.x/trunk/itest/scaclient-api-osgi/src/test/java/test/scaclient/SCAClientTestCase.java >> (original) >> +++ >> tuscany/sca-java-2.x/trunk/itest/scaclient-api-osgi/src/test/java/test/scaclient/SCAClientTestCase.java >> Wed Jan 20 16:42:59 2010 >> @@ -19,6 +19,8 @@ >> >> package test.scaclient; >> >> +import java.net.URI; >> + >> import itest.HelloworldService; >> import junit.framework.TestCase; >> >> @@ -26,6 +28,8 @@ >> import org.apache.tuscany.sca.node.ContributionLocationHelper; >> import org.apache.tuscany.sca.node.Node; >> import org.apache.tuscany.sca.node.NodeFactory; >> +import org.oasisopen.sca.NoSuchDomainException; >> +import org.oasisopen.sca.NoSuchServiceException; >> import org.oasisopen.sca.client.SCAClientFactory; >> >> /** >> @@ -40,16 +44,14 @@ >> �...@override >> protected void setUp() throws Exception { >> String location = >> ContributionLocationHelper.getContributionLocation(HelloworldService.class); >> - node = >> NodeFactory.newInstance().createNode("Helloworld.composite", new >> Contribution("test", "./target/classes")); >> + node = >> NodeFactory.getInstance().createNode("Helloworld.composite", new >> Contribution("test", "./target/classes")); >> System.out.println("SCA Node API ClassLoader: " + >> node.getClass().getClassLoader()); >> node.start(); >> } >> >> - public void testInvoke() throws Exception { >> - // At the moment the SCAClientFactory assumes that only one >> domain is active >> - // in a JVM. So we pass in null for the domain name and get what >> we're given >> + public void testInvoke() throws NoSuchServiceException, >> NoSuchDomainException { >> HelloworldService service = >> - SCAClientFactory.newInstance(null).getService(HelloworldService.class, >> "HelloworldComponent"); >> + >> SCAClientFactory.newInstance(URI.create("http://tuscany.apache.org/sca/1.1/domains/default")).getService(HelloworldService.class, >> "HelloworldComponent"); >> String result = service.sayHello("petra"); >> assertEquals("Hello petra", result); >> System.out.println("Result from SCAClient call = " + result); >> >> Modified: >> tuscany/sca-java-2.x/trunk/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java >> URL: >> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java?rev=901270&r1=901269&r2=901270&view=diff >> >> ============================================================================== >> --- >> tuscany/sca-java-2.x/trunk/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java >> (original) >> +++ >> tuscany/sca-java-2.x/trunk/itest/scaclient-api/src/test/java/test/scaclient/SCAClientTestCase.java >> Wed Jan 20 16:42:59 2010 >> @@ -38,7 +38,7 @@ >> >> �...@override >> protected void setUp() throws Exception { >> - node = NodeFactory.newInstance().createNode(); >> + node = NodeFactory.getInstance().createNode(); >> node.start(); >> } >> >> >> Modified: >> tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java >> URL: >> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java?rev=901270&r1=901269&r2=901270&view=diff >> >> ============================================================================== >> --- >> tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java >> (original) >> +++ >> tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java >> Wed Jan 20 16:42:59 2010 >> @@ -33,6 +33,7 @@ >> >> Endpoint getEndpoint(String uri); >> void updateEndpoint(String uri, Endpoint endpoint); >> + List<Endpoint> findEndpoint(String uri); >> List<Endpoint> findEndpoint(EndpointReference endpointReference); >> List<Endpoint> getEndpoints(); >> >> >> Modified: >> tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointRegistryImpl.java >> URL: >> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointRegistryImpl.java?rev=901270&r1=901269&r2=901270&view=diff >> >> ============================================================================== >> --- >> tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointRegistryImpl.java >> (original) >> +++ >> tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointRegistryImpl.java >> Wed Jan 20 16:42:59 2010 >> @@ -115,7 +115,7 @@ >> return foundEndpoints; >> } >> >> - protected List<Endpoint> findEndpoint(String uri) { >> + public List<Endpoint> findEndpoint(String uri) { >> List<Endpoint> foundEndpoints = new ArrayList<Endpoint>(); >> for (Endpoint endpoint : endpoints) { >> if (matches(uri, endpoint.getURI())) { >> >> Modified: >> tuscany/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java >> URL: >> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java?rev=901270&r1=901269&r2=901270&view=diff >> >> ============================================================================== >> --- >> tuscany/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java >> (original) >> +++ >> tuscany/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java >> Wed Jan 20 16:42:59 2010 >> @@ -197,32 +197,31 @@ >> } >> >> public List<Endpoint> findEndpoint(EndpointReference endpointReference) >> { >> - List<Endpoint> foundEndpoints = new ArrayList<Endpoint>(); >> - >> logger.fine("Find endpoint for reference - " + endpointReference); >> - >> if (endpointReference.getReference() != null) { >> Endpoint targetEndpoint = >> endpointReference.getTargetEndpoint(); >> - >> - for (Object v : map.values()) { >> - Endpoint endpoint = (Endpoint)v; >> - logger.fine("Matching against - " + endpoint); >> - if (matches(targetEndpoint.getURI(), endpoint.getURI())) >> { >> - if (!isLocal(endpoint)) { >> - endpoint.setRemote(true); >> - } >> - // if (!entry.isPrimary()) { >> - ((RuntimeEndpoint)endpoint).bind(registry, this); >> - // } >> - foundEndpoints.add(endpoint); >> - logger.fine("Found endpoint with matching service - >> " + endpoint); >> + return findEndpoint(targetEndpoint.getURI()); >> + } >> + return new ArrayList<Endpoint>(); >> + } >> + >> + public List<Endpoint> findEndpoint(String uri) { >> + List<Endpoint> foundEndpoints = new ArrayList<Endpoint>(); >> + for (Object v : map.values()) { >> + Endpoint endpoint = (Endpoint)v; >> + logger.fine("Matching against - " + endpoint); >> + if (matches(uri, endpoint.getURI())) { >> + if (!isLocal(endpoint)) { >> + endpoint.setRemote(true); >> } >> - // else the service name doesn't match >> + ((RuntimeEndpoint)endpoint).bind(registry, this); >> + foundEndpoints.add(endpoint); >> + logger.fine("Found endpoint with matching service - " + >> endpoint); >> } >> } >> - >> return foundEndpoints; >> } >> + >> >> private boolean isLocal(Endpoint endpoint) { >> return localEndpoints.contains(endpoint.getURI()); >> >> Modified: >> tuscany/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java >> URL: >> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java?rev=901270&r1=901269&r2=901270&view=diff >> >> ============================================================================== >> --- >> tuscany/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java >> (original) >> +++ >> tuscany/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java >> Wed Jan 20 16:42:59 2010 >> @@ -319,55 +319,61 @@ >> } >> >> public List<Endpoint> findEndpoint(EndpointReference endpointReference) >> { >> - List<Endpoint> foundEndpoints = new ArrayList<Endpoint>(); >> - >> logger.fine("Find endpoint for reference - " + endpointReference); >> >> if (endpointReference.getReference() != null) { >> Endpoint targetEndpoint = >> endpointReference.getTargetEndpoint(); >> - >> - // in the failure case we repeat the look up after a short >> - // delay to take account of tribes replication delays >> - int repeat = FIND_REPEAT_COUNT; >> - >> - while (repeat > 0){ >> - for (Object v : map.values()) { >> - Endpoint endpoint = (Endpoint)v; >> - // TODO: implement more complete matching >> - logger.fine("Matching against - " + endpoint); >> - if (matches(targetEndpoint.getURI(), >> endpoint.getURI())) { >> - MapEntry entry = >> map.getInternal(endpoint.getURI()); >> - if (!isLocal(entry)) { >> - endpoint.setRemote(true); >> - } >> - // if (!entry.isPrimary()) { >> - ((RuntimeEndpoint) endpoint).bind(registry, >> this); >> - // } >> - foundEndpoints.add(endpoint); >> - logger.fine("Found endpoint with matching ervice >> - " + endpoint); >> - repeat = 0; >> - } >> - // else the service name doesn't match >> - } >> - >> - if (foundEndpoints.size() == 0) { >> - // the service name doesn't match any endpoints so >> wait a little and try >> - // again in case this is caused by tribes synch >> delays >> - logger.info("Repeating endpoint reference match - " + >> endpointReference); >> - repeat--; >> - try { >> - Thread.sleep(1000); >> - } catch(Exception ex){ >> - // do nothing >> - repeat=0; >> + return findEndpoint(targetEndpoint.getURI()); >> + } >> + >> + return new ArrayList<Endpoint>(); >> + } >> + >> + public List<Endpoint> findEndpoint(String uri) { >> + List<Endpoint> foundEndpoints = new ArrayList<Endpoint>(); >> + >> + // in the failure case we repeat the look up after a short >> + // delay to take account of tribes replication delays >> + int repeat = FIND_REPEAT_COUNT; >> + >> + while (repeat > 0){ >> + for (Object v : map.values()) { >> + Endpoint endpoint = (Endpoint)v; >> + // TODO: implement more complete matching >> + logger.fine("Matching against - " + endpoint); >> + if (matches(uri, endpoint.getURI())) { >> + MapEntry entry = map.getInternal(endpoint.getURI()); >> + if (!isLocal(entry)) { >> + endpoint.setRemote(true); >> } >> + // if (!entry.isPrimary()) { >> + ((RuntimeEndpoint) endpoint).bind(registry, this); >> + // } >> + foundEndpoints.add(endpoint); >> + logger.fine("Found endpoint with matching service - >> " + endpoint); >> + repeat = 0; >> + } >> + // else the service name doesn't match >> + } >> + >> + if (foundEndpoints.size() == 0) { >> + // the service name doesn't match any endpoints so wait a >> little and try >> + // again in case this is caused by tribes synch delays >> + logger.info("Repeating endpoint reference match - " + >> uri); >> + repeat--; >> + try { >> + Thread.sleep(1000); >> + } catch(Exception ex){ >> + // do nothing >> + repeat=0; >> } >> } >> } >> - >> + >> return foundEndpoints; >> } >> >> + >> private boolean isLocal(MapEntry entry) { >> return >> entry.getPrimary().equals(map.getChannel().getLocalMember(false)); >> } >> >> Modified: >> tuscany/sca-java-2.x/trunk/modules/sca-client-impl/META-INF/MANIFEST.MF >> URL: >> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/sca-client-impl/META-INF/MANIFEST.MF?rev=901270&r1=901269&r2=901270&view=diff >> >> ============================================================================== >> --- >> tuscany/sca-java-2.x/trunk/modules/sca-client-impl/META-INF/MANIFEST.MF >> (original) >> +++ >> tuscany/sca-java-2.x/trunk/modules/sca-client-impl/META-INF/MANIFEST.MF Wed >> Jan 20 16:42:59 2010 >> @@ -6,8 +6,11 @@ >> 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 >> >> Modified: >> tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java >> URL: >> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java?rev=901270&r1=901269&r2=901270&view=diff >> >> ============================================================================== >> --- >> tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java >> (original) >> +++ >> tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java >> Wed Jan 20 16:42:59 2010 >> @@ -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 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(); >> } >> } >> >> Added: >> tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientProxyHandler.java >> URL: >> http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientProxyHandler.java?rev=901270&view=auto >> >> ============================================================================== >> --- >> tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientProxyHandler.java >> (added) >> +++ >> tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientProxyHandler.java >> Wed Jan 20 16:42:59 2010 >> @@ -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; >> + } >> + >> +} >> >> >
