diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-28 15:04:39 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-28 15:04:39 +0000 |
commit | 88d9e951a4d8cbb72ae4ddfe5695cb380ec6c2bb (patch) | |
tree | f21fdf7e13b0a28041281c342d8996587a4aeca1 /sca-java-2.x/trunk/modules/sca-client-rmi/src | |
parent | 3abdf3411e2ecc8d72748373d09914e152b4d416 (diff) |
Update to use the hazelcast client registry
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@904115 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/sca-client-rmi/src')
-rw-r--r-- | sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientFactoryFinderImpl.java | 49 | ||||
-rw-r--r-- | sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientFactoryImpl.java | 114 | ||||
-rw-r--r-- | sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientModuleActivator.java | 37 | ||||
-rw-r--r-- | sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientProxyHandler.java | 44 | ||||
-rw-r--r-- | sca-java-2.x/trunk/modules/sca-client-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator | 18 | ||||
-rw-r--r-- | sca-java-2.x/trunk/modules/sca-client-rmi/src/test/java/org/apache/tuscany/sca/client/rmi/ClientTestCase.java (renamed from sca-java-2.x/trunk/modules/sca-client-rmi/src/test/java/org/apache/tuscany/sca/client/rmi/HJJTestcase.java) | 17 |
6 files changed, 195 insertions, 84 deletions
diff --git a/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientFactoryFinderImpl.java b/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientFactoryFinderImpl.java new file mode 100644 index 0000000000..ab87ea27d4 --- /dev/null +++ b/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientFactoryFinderImpl.java @@ -0,0 +1,49 @@ +/*
+ * Copyright(C) OASIS(R) 2005,2009. All Rights Reserved.
+ * OASIS trademark, IPR and other policies apply.
+ */
+package org.apache.tuscany.sca.client.rmi;
+
+import java.net.URI;
+import java.util.Properties;
+
+import org.oasisopen.sca.NoSuchDomainException;
+import org.oasisopen.sca.ServiceRuntimeException;
+import org.oasisopen.sca.client.SCAClientFactory;
+import org.oasisopen.sca.client.SCAClientFactoryFinder;
+
+/**
+ * A Tuscany specific implementation of an SCAClientFactoryFinder which finds
+ * hard codes the use of the Tuscany SCAClientFactory instead of doscovering it.
+ *
+ * @see SCAClientFactoryFinder
+ * @see SCAClientFactory
+ */
+public class SCAClientFactoryFinderImpl implements SCAClientFactoryFinder {
+
+ /**
+ * Public Constructor
+ */
+ public SCAClientFactoryFinderImpl() {
+ }
+
+ /**
+ * Creates an instance of the SCAClientFactorySPI implementation.
+ * This discovers the SCAClientFactorySPI Implementation and instantiates
+ * the provider's implementation.
+ *
+ * @param properties Properties that may be used when creating a new
+ * instance of the SCAClient
+ * @param classLoader ClassLoader that may be used when creating a new
+ * instance of the SCAClient
+ * @return new instance of the SCAClientFactory
+ * @throws ServiceRuntimeException Failed to create SCAClientFactory
+ * Implementation.
+ */
+ public SCAClientFactory find(Properties properties,
+ ClassLoader classLoader,
+ URI domainURI ) throws NoSuchDomainException, ServiceRuntimeException {
+ return new SCAClientFactoryImpl(domainURI);
+ }
+
+}
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 7dad6a28db..cde91739c0 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 @@ -24,100 +24,76 @@ 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.NodeFactory;
-import org.apache.tuscany.sca.node.NodeFinder;
+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;
public class SCAClientFactoryImpl extends SCAClientFactory {
- private EndpointRegistry endpointRegistry;
+ public static void setSCAClientFactoryFinder(SCAClientFactoryFinder factoryFinder) {
+ SCAClientFactory.factoryFinder = factoryFinder;
+ }
+
private ExtensionPointRegistry extensionsRegistry;
+ private EndpointRegistry endpointRegistry;
+ private NodeFactoryImpl nodeFactory;
- public SCAClientFactoryImpl() throws NoSuchDomainException {
- super(URI.create(Node.DEFAULT_DOMAIN_URI));
- }
-
public SCAClientFactoryImpl(URI domainURI) throws NoSuchDomainException {
super(domainURI);
- NodeImpl node = (NodeImpl)NodeFactory.getInstance().createNode(domainURI);
- if (node.getExtensionPoints() == null) {
- // No local nodes have been started (for this domain?)
- // ideally we'll use the Hazelcast client but for now just start a node
- node.start();
+
+ this.nodeFactory = (NodeFactoryImpl)NodeFactory.getInstance();
+ this.extensionsRegistry = nodeFactory.getExtensionPoints();
+ 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.extensionsRegistry = node.getExtensionPoints();
- UtilityExtensionPoint utilities = extensionsRegistry.getExtensionPoint(UtilityExtensionPoint.class);
- DomainRegistryFactory domainRegistryFactory = utilities.getUtility(DomainRegistryFactory.class);
- this.endpointRegistry = domainRegistryFactory.getEndpointRegistry(getDomainURI().toString(), node.getConfiguration().getDomainName());
- }
-
+ }
+
@Override
- @SuppressWarnings("unchecked")
public <T> T getService(Class<T> serviceInterface, String serviceName) throws NoSuchServiceException, NoSuchDomainException {
- 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);
+
+ if (endpointRegistry != null) {
+ List<Endpoint> eps = endpointRegistry.findEndpoint(serviceName);
+ if (eps == null || eps.size() < 1) {
+ throw new NoSuchServiceException(serviceName);
+ }
+ 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);
+ }
}
- }
-
- 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();
-// }
- return getDomainURI().toString();
- }
-
- public void stop() {
- extensionsRegistry.stop();
- }
- public EndpointRegistry getEndpointRegistry() {
- return endpointRegistry;
- }
+ String uri = getDomainURI().toString();
+ if (uri.startsWith("tuscany:")) {
+ uri = uri.replace("tuscany:", "tuscanyClient:");
+ }
+ InvocationHandler handler = new SCAClientProxyHandler(nodeFactory, uri, serviceName);
+ return (T)Proxy.newProxyInstance(serviceInterface.getClassLoader(), new Class[] {serviceInterface}, handler);
- 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);
+ private Node findLocalNode(Endpoint endpoint) {
+ for (Node node : nodeFactory.getNodes().values()) {
+ for (Endpoint ep : ((NodeImpl)node).getServiceEndpoints()) {
+ if (endpoint.getURI().equals(ep.getURI())) {
+ return node;
+ }
+ }
}
- 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);
+ return null;
}
+
}
diff --git a/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientModuleActivator.java b/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientModuleActivator.java new file mode 100644 index 0000000000..af9ac1d9c5 --- /dev/null +++ b/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/java/org/apache/tuscany/sca/client/rmi/SCAClientModuleActivator.java @@ -0,0 +1,37 @@ +/*
+ * 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.rmi;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ModuleActivator;
+
+public class SCAClientModuleActivator implements ModuleActivator {
+
+ public SCAClientModuleActivator(ExtensionPointRegistry registry) {
+ }
+
+ public void start() {
+ SCAClientFactoryImpl.setSCAClientFactoryFinder(new SCAClientFactoryFinderImpl());
+ }
+
+ public void stop() {
+
+ }
+}
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 b4acaabbdf..6d182c61a7 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 @@ -21,6 +21,7 @@ package org.apache.tuscany.sca.client.rmi; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
+import java.net.URI;
import java.util.List;
import org.apache.tuscany.sca.assembly.AssemblyFactory;
@@ -29,23 +30,32 @@ import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.binding.rmi.provider.RMIBindingInvoker;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.host.rmi.ExtensibleRMIHost;
import org.apache.tuscany.sca.host.rmi.RMIHost;
import org.apache.tuscany.sca.host.rmi.RMIHostExtensionPoint;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.apache.tuscany.sca.node.impl.NodeFactoryImpl;
+import org.apache.tuscany.sca.runtime.DomainRegistryFactory;
import org.apache.tuscany.sca.runtime.EndpointRegistry;
import org.oasisopen.sca.NoSuchServiceException;
public class SCAClientProxyHandler implements InvocationHandler {
+ protected NodeFactoryImpl nodeFactory;
+ protected ExtensionPointRegistry extensionsRegistry;
protected EndpointRegistry endpointRegistry;
protected EndpointReference endpointReference;
protected String serviceName;
protected RMIHost rmiHost;
+ private String domainURI;
- public SCAClientProxyHandler(String serviceName, ExtensionPointRegistry extensionsRegistry, EndpointRegistry endpointRegistry) {
- this.endpointRegistry = endpointRegistry;
+ public SCAClientProxyHandler(NodeFactoryImpl nodeFactory, String domainURI, String serviceName) {
+ this.nodeFactory = nodeFactory;
+ this.domainURI = domainURI;
this.serviceName = serviceName;
-
+ this.extensionsRegistry = nodeFactory.getExtensionPoints();
RMIHostExtensionPoint rmiHosts = extensionsRegistry.getExtensionPoint(RMIHostExtensionPoint.class);
this.rmiHost = new ExtensibleRMIHost(rmiHosts);
@@ -60,16 +70,28 @@ public class SCAClientProxyHandler implements InvocationHandler { }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ Node node = null;
+ try {
- List<Endpoint> endpoints = endpointRegistry.findEndpoint(endpointReference);
- if (endpoints.size() <1 ) {
- throw new NoSuchServiceException(serviceName);
- }
+ node = NodeFactory.newInstance().createNode(URI.create(domainURI)).start();
+ UtilityExtensionPoint utilities = extensionsRegistry.getExtensionPoint(UtilityExtensionPoint.class);
+ DomainRegistryFactory domainRegistryFactory = utilities.getUtility(DomainRegistryFactory.class);
+ this.endpointRegistry = domainRegistryFactory.getEndpointRegistry(null, domainURI);
- String uri = endpoints.get(0).getBinding().getURI();
- RMIBindingInvoker invoker = new RMIBindingInvoker(rmiHost, uri, method);
+ List<Endpoint> endpoints = endpointRegistry.findEndpoint(endpointReference);
+ if (endpoints.size() <1 ) {
+ throw new NoSuchServiceException(serviceName);
+ }
- return invoker.invokeTarget(args);
- }
+ String uri = endpoints.get(0).getBinding().getURI();
+ RMIBindingInvoker invoker = new RMIBindingInvoker(rmiHost, uri, method);
+ return invoker.invokeTarget(args);
+
+ } finally {
+ if (node != null) {
+ node.stop();
+ }
+ }
+ }
}
diff --git a/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..aef20a3d23 --- /dev/null +++ b/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -0,0 +1,18 @@ +# 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. +# Implementation class for the ModuleActivator +org.apache.tuscany.sca.client.rmi.SCAClientModuleActivator;priority=200 diff --git a/sca-java-2.x/trunk/modules/sca-client-rmi/src/test/java/org/apache/tuscany/sca/client/rmi/HJJTestcase.java b/sca-java-2.x/trunk/modules/sca-client-rmi/src/test/java/org/apache/tuscany/sca/client/rmi/ClientTestCase.java index 2db6db4ebf..8ca5e0748b 100644 --- a/sca-java-2.x/trunk/modules/sca-client-rmi/src/test/java/org/apache/tuscany/sca/client/rmi/HJJTestcase.java +++ b/sca-java-2.x/trunk/modules/sca-client-rmi/src/test/java/org/apache/tuscany/sca/client/rmi/ClientTestCase.java @@ -23,18 +23,27 @@ import static org.junit.Assert.assertEquals; import java.net.URI;
-import org.junit.Test;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.Ignore;
import org.oasisopen.sca.NoSuchDomainException;
import org.oasisopen.sca.NoSuchServiceException;
import calculator.CalculatorService;
-public class HJJTestcase {
+@Ignore
+public class ClientTestCase {
- @Test
+ //@Test
public void foo() throws NoSuchServiceException, NoSuchDomainException {
- SCAClientFactoryImpl cf = new SCAClientFactoryImpl(URI.create("tribes:foo"));
+
+ 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"));
CalculatorService service = cf.getService(CalculatorService.class, "CalculatorServiceComponent");
assertEquals(3, service.add(1, 2), 0);
+
+ node.stop();
}
}
|