From 40aa7960a748c80a2465d5ca78e8f91d43296c8e Mon Sep 17 00:00:00 2001 From: rfeng Date: Fri, 29 Jan 2010 03:34:21 +0000 Subject: Refactor the DomainRegistryFactory to be extensions of DomainRegistryFactoryExtensionPoint git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@904367 13f79535-47bb-0310-9956-ffa450edef68 --- .../test/java/itest/TwoRemoteNodesTestCase.java | 2 +- .../itest/nodes/two-nodes-two-vms-test/build.xml | 2 +- .../nodes/two-nodes-two-vms-test/client-config.xml | 4 +- .../nodes/two-nodes-two-vms-test/server-config.xml | 4 +- ...org.apache.tuscany.sca.assembly.EndpointFactory | 18 -- .../provider/RuntimeSCAServiceBindingProvider.java | 5 +- .../sca/runtime/BaseDomainRegistryFactory.java | 114 ++++++++++++ .../tuscany/sca/runtime/BaseEndpointRegistry.java | 202 +++++++++++++++++++++ ...DefaultDomainRegistryFactoryExtensionPoint.java | 91 ++++++++++ .../tuscany/sca/runtime/DomainRegistryFactory.java | 3 +- .../DomainRegistryFactoryExtensionPoint.java | 33 ++++ .../tuscany/sca/runtime/EndpointRegistry.java | 28 ++- .../sca/runtime/ExtensibleDomainRegistry.java | 96 ++++++++++ ...sca.runtime.DomainRegistryFactoryExtensionPoint | 17 ++ .../core/assembly/impl/EndpointRegistryImpl.java | 103 +---------- .../assembly/impl/LocalDomainRegistryFactory.java | 49 +++++ .../core/runtime/DefaultDomainRegistryFactory.java | 175 ------------------ ...pache.tuscany.sca.runtime.DomainRegistryFactory | 9 +- ...org.apache.tuscany.sca.runtime.EndpointRegistry | 18 -- .../apache/tuscany/sca/domain/node/DomainNode.java | 5 +- .../sca/endpoint/dht/DHTDomainRegistryFactory.java | 51 ++++++ .../sca/endpoint/dht/OverlayEndpointRegistry.java | 3 +- ...pache.tuscany.sca.runtime.DomainRegistryFactory | 17 ++ ...org.apache.tuscany.sca.runtime.EndpointRegistry | 18 -- .../HazelcastClientDomainRegistryFactory.java | 49 +++++ ...pache.tuscany.sca.runtime.DomainRegistryFactory | 17 ++ ...org.apache.tuscany.sca.runtime.EndpointRegistry | 18 -- .../hazelcast/HazelcastDomainRegistryFactory.java | 49 +++++ .../hazelcast/HazelcastEndpointRegistry.java | 116 +----------- ...pache.tuscany.sca.runtime.DomainRegistryFactory | 17 ++ ...org.apache.tuscany.sca.runtime.EndpointRegistry | 18 -- .../tribes/ReplicatedEndpointRegistry.java | 178 ++---------------- .../tribes/TribesDomainRegistryFactory.java | 49 +++++ ...pache.tuscany.sca.runtime.DomainRegistryFactory | 17 ++ ...org.apache.tuscany.sca.runtime.EndpointRegistry | 17 -- .../endpoint/zookeeper/DistributedRegistry.java | 3 +- .../zookeeper/ZooKeeperDomainRegistryFactory.java | 49 +++++ ...pache.tuscany.sca.runtime.DomainRegistryFactory | 17 ++ ...org.apache.tuscany.sca.runtime.EndpointRegistry | 17 -- .../discovery/impl/DomainDiscoveryService.java | 5 +- .../tuscany/sca/node/impl/NodeFactoryImpl.java | 3 +- .../org/apache/tuscany/sca/node/impl/NodeImpl.java | 10 +- .../sca/client/impl/SCAClientFactoryImpl.java | 5 +- .../org.apache.tuscany.sca.core.ModuleActivator | 2 +- .../org.oasisopen.sca.client.SCAClientFactory | 18 +- .../sca/client/rmi/SCAClientFactoryImpl.java | 8 +- .../sca/client/rmi/SCAClientProxyHandler.java | 5 +- .../org.apache.tuscany.sca.core.ModuleActivator | 2 +- .../org.oasisopen.sca.client.SCAClientFactory | 17 ++ 49 files changed, 1058 insertions(+), 715 deletions(-) delete mode 100644 sca-java-2.x/trunk/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.EndpointFactory create mode 100644 sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseDomainRegistryFactory.java create mode 100644 sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseEndpointRegistry.java create mode 100644 sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultDomainRegistryFactoryExtensionPoint.java create mode 100644 sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactoryExtensionPoint.java create mode 100644 sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ExtensibleDomainRegistry.java create mode 100644 sca-java-2.x/trunk/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactoryExtensionPoint create mode 100644 sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/LocalDomainRegistryFactory.java delete mode 100644 sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/DefaultDomainRegistryFactory.java delete mode 100644 sca-java-2.x/trunk/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry create mode 100644 sca-java-2.x/trunk/modules/endpoint-dht/src/main/java/org/apache/tuscany/sca/endpoint/dht/DHTDomainRegistryFactory.java create mode 100644 sca-java-2.x/trunk/modules/endpoint-dht/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory delete mode 100644 sca-java-2.x/trunk/modules/endpoint-dht/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry create mode 100644 sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/client/HazelcastClientDomainRegistryFactory.java create mode 100644 sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory delete mode 100644 sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry create mode 100644 sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastDomainRegistryFactory.java create mode 100644 sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory delete mode 100644 sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry create mode 100644 sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/TribesDomainRegistryFactory.java create mode 100644 sca-java-2.x/trunk/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory delete mode 100644 sca-java-2.x/trunk/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry create mode 100644 sca-java-2.x/trunk/modules/endpoint-zookeeper/src/main/java/org/apache/tuscany/sca/endpoint/zookeeper/ZooKeeperDomainRegistryFactory.java create mode 100644 sca-java-2.x/trunk/modules/endpoint-zookeeper/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory delete mode 100644 sca-java-2.x/trunk/modules/endpoint-zookeeper/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry (limited to 'sca-java-2.x') diff --git a/sca-java-2.x/trunk/itest/nodes/one-jvm-hazelcast/src/test/java/itest/TwoRemoteNodesTestCase.java b/sca-java-2.x/trunk/itest/nodes/one-jvm-hazelcast/src/test/java/itest/TwoRemoteNodesTestCase.java index 7e3cf0c3e6..1c20911da2 100644 --- a/sca-java-2.x/trunk/itest/nodes/one-jvm-hazelcast/src/test/java/itest/TwoRemoteNodesTestCase.java +++ b/sca-java-2.x/trunk/itest/nodes/one-jvm-hazelcast/src/test/java/itest/TwoRemoteNodesTestCase.java @@ -64,7 +64,7 @@ public class TwoRemoteNodesTestCase{ // assertNotNull(scaClientService); // assertEquals("Hello Petra", scaClientService.sayHello("Petra")); - Helloworld scaClientClient = SCAClientFactory.newInstance(URI.create("TwoRemoteNodesTestCase")).getService(Helloworld.class, "HelloworldClient"); + Helloworld scaClientClient = SCAClientFactory.newInstance(URI.create("tuscany:TwoRemoteNodesTestCase")).getService(Helloworld.class, "HelloworldClient"); assertNotNull(scaClientClient); assertEquals("Hi Hello Petra", scaClientClient.sayHello("Petra")); diff --git a/sca-java-2.x/trunk/itest/nodes/two-nodes-two-vms-test/build.xml b/sca-java-2.x/trunk/itest/nodes/two-nodes-two-vms-test/build.xml index 3d77230541..a89e2e34c7 100644 --- a/sca-java-2.x/trunk/itest/nodes/two-nodes-two-vms-test/build.xml +++ b/sca-java-2.x/trunk/itest/nodes/two-nodes-two-vms-test/build.xml @@ -27,7 +27,7 @@ - + diff --git a/sca-java-2.x/trunk/itest/nodes/two-nodes-two-vms-test/client-config.xml b/sca-java-2.x/trunk/itest/nodes/two-nodes-two-vms-test/client-config.xml index b47de3d2cb..5afc1eddfa 100644 --- a/sca-java-2.x/trunk/itest/nodes/two-nodes-two-vms-test/client-config.xml +++ b/sca-java-2.x/trunk/itest/nodes/two-nodes-two-vms-test/client-config.xml @@ -21,8 +21,8 @@ xmlns="http://tuscany.apache.org/xmlns/sca/1.1" xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" uri="http://sample/nodes/TestNode1" - domain="http://domain1" - domainRegistry="tribes:default"> + domainRegistry = "tribes://228.0.0.100:50000" + domain="http://domain1"> diff --git a/sca-java-2.x/trunk/itest/nodes/two-nodes-two-vms-test/server-config.xml b/sca-java-2.x/trunk/itest/nodes/two-nodes-two-vms-test/server-config.xml index d4d09c0d0f..2067c9e96b 100644 --- a/sca-java-2.x/trunk/itest/nodes/two-nodes-two-vms-test/server-config.xml +++ b/sca-java-2.x/trunk/itest/nodes/two-nodes-two-vms-test/server-config.xml @@ -21,8 +21,8 @@ xmlns="http://tuscany.apache.org/xmlns/sca/1.1" xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" uri="http://sample/nodes/TestNode1" - domain="http://domain1" - domainRegistry="tribes:default"> + domainRegistry = "tribes://228.0.0.100:50000" + domain="http://domain1"> diff --git a/sca-java-2.x/trunk/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.EndpointFactory b/sca-java-2.x/trunk/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.EndpointFactory deleted file mode 100644 index ebbb4e93a7..0000000000 --- a/sca-java-2.x/trunk/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.EndpointFactory +++ /dev/null @@ -1,18 +0,0 @@ -# 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. - -org.apache.tuscany.sca.assembly.DefaultEndpointFactory diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/RuntimeSCAServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/RuntimeSCAServiceBindingProvider.java index 500b4ba304..84e69a79a4 100644 --- a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/RuntimeSCAServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/RuntimeSCAServiceBindingProvider.java @@ -28,13 +28,13 @@ import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.SCABindingFactory; 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.interfacedef.InterfaceContract; import org.apache.tuscany.sca.provider.BindingProviderFactory; import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; import org.apache.tuscany.sca.provider.ServiceBindingProvider; import org.apache.tuscany.sca.runtime.DomainRegistryFactory; import org.apache.tuscany.sca.runtime.EndpointRegistry; +import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistry; import org.apache.tuscany.sca.runtime.RuntimeComponentService; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; @@ -103,8 +103,7 @@ public class RuntimeSCAServiceBindingProvider implements ServiceBindingProvider // find if the node config is for distributed endpoints // TODO: temp, need a much better way to do this if (distributedProviderFactory != null) { - UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - DomainRegistryFactory domainRegistryFactory = utilities.getUtility(DomainRegistryFactory.class); + DomainRegistryFactory domainRegistryFactory = new ExtensibleDomainRegistry(extensionPoints); Collection eprs = domainRegistryFactory.getEndpointRegistries(); if (eprs.size() > 0) { String eprName = eprs.iterator().next().getClass().getName(); diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseDomainRegistryFactory.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseDomainRegistryFactory.java new file mode 100644 index 0000000000..97b3f81017 --- /dev/null +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseDomainRegistryFactory.java @@ -0,0 +1,114 @@ +/* + * 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.runtime; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.LifeCycleListener; + +/** + * The utility responsible for finding the endpoint regstry by the scheme and creating instances for the + * given domain + */ +public abstract class BaseDomainRegistryFactory implements DomainRegistryFactory, LifeCycleListener { + protected ExtensionPointRegistry registry; + protected Map endpointRegistries = new ConcurrentHashMap(); + protected List listeners = new ArrayList(); + + /** + * @param extensionRegistry + */ + public BaseDomainRegistryFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + public void start() { + } + + public synchronized EndpointRegistry getEndpointRegistry(String endpointRegistryURI, String domainURI) { + if (endpointRegistryURI == null) { + endpointRegistryURI = domainURI; + } + + Object key = getKey(endpointRegistryURI, domainURI); + + EndpointRegistry endpointRegistry = endpointRegistries.get(key); + if (endpointRegistry != null) { + return endpointRegistry; + } + + endpointRegistry = createEndpointRegistry(endpointRegistryURI, domainURI); + + if (endpointRegistry instanceof LifeCycleListener) { + ((LifeCycleListener)endpointRegistry).start(); + } + + for (EndpointListener listener : listeners) { + endpointRegistry.addListener(listener); + } + endpointRegistries.put(key, endpointRegistry); + return endpointRegistry; + } + + protected Object getKey(String endpointRegistryURI, String domainURI) { + return endpointRegistryURI + "," + domainURI; + } + + protected abstract EndpointRegistry createEndpointRegistry(String endpointRegistryURI, String domainURI); + + public void stop() { + for (EndpointRegistry endpointRegistry : endpointRegistries.values()) { + if (endpointRegistry instanceof LifeCycleListener) { + ((LifeCycleListener)endpointRegistry).stop(); + } + } + endpointRegistries.clear(); + listeners.clear(); + } + + public synchronized Collection getEndpointRegistries() { + return new ArrayList(endpointRegistries.values()); + } + + public synchronized void addListener(EndpointListener listener) { + listeners.add(listener); + for (EndpointRegistry registry : endpointRegistries.values()) { + registry.addListener(listener); + } + } + + public synchronized List getListeners() { + return listeners; + } + + public synchronized void removeListener(EndpointListener listener) { + listeners.remove(listener); + for (EndpointRegistry registry : endpointRegistries.values()) { + registry.removeListener(listener); + } + } + +} diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseEndpointRegistry.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseEndpointRegistry.java new file mode 100644 index 0000000000..5646916075 --- /dev/null +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseEndpointRegistry.java @@ -0,0 +1,202 @@ +/* + * 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.runtime; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.logging.Logger; + +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.LifeCycleListener; + +/** + * A replicated EndpointRegistry based on Apache Tomcat Tribes + */ +public abstract class BaseEndpointRegistry implements EndpointRegistry, LifeCycleListener { + protected final static Logger logger = Logger.getLogger(BaseEndpointRegistry.class.getName()); + + protected String domainRegistryURI; + protected String domainURI; + + protected List endpointreferences = new CopyOnWriteArrayList(); + protected List listeners = new CopyOnWriteArrayList(); + protected ExtensionPointRegistry registry; + protected Map attributes; + + public BaseEndpointRegistry(ExtensionPointRegistry registry, + Map attributes, + String domainRegistryURI, + String domainURI) { + this.registry = registry; + this.domainURI = domainURI; + this.domainRegistryURI = domainRegistryURI; + this.attributes = attributes; + } + + public abstract void addEndpoint(Endpoint endpoint); + + public void addEndpointReference(EndpointReference endpointReference) { + endpointreferences.add(endpointReference); + logger.fine("Add endpoint reference - " + endpointReference); + } + + public void addListener(EndpointListener listener) { + listeners.add(listener); + } + + protected void endpointAdded(Endpoint endpoint) { + ((RuntimeEndpoint)endpoint).bind(registry, this); + for (EndpointListener listener : listeners) { + listener.endpointAdded(endpoint); + } + } + + protected void endpointRemoved(Endpoint endpoint) { + ((RuntimeEndpoint)endpoint).bind(registry, this); + for (EndpointListener listener : listeners) { + listener.endpointRemoved(endpoint); + } + } + + protected void endpointUpdated(Endpoint oldEp, Endpoint newEp) { + ((RuntimeEndpoint)newEp).bind(registry, this); + for (EndpointListener listener : listeners) { + listener.endpointUpdated(oldEp, newEp); + } + } + + public List findEndpoint(EndpointReference endpointReference) { + logger.fine("Find endpoint for reference - " + endpointReference); + + if (endpointReference.getReference() != null) { + Endpoint targetEndpoint = endpointReference.getTargetEndpoint(); + return findEndpoint(targetEndpoint.getURI()); + } + + return new ArrayList(); + } + + public abstract List findEndpoint(String uri); + + public List findEndpointReference(Endpoint endpoint) { + return endpointreferences; + } + + public abstract Endpoint getEndpoint(String uri); + + public List getEndpointReferences() { + return endpointreferences; + } + + public abstract Collection getEndpoints(); + + public List getListeners() { + return listeners; + } + + /** + * Check if a serviceURI matches the given endpoint URI + * @param serviceURI + * @param endpointURI + * @return + */ + protected boolean matches(String serviceURI, String endpointURI) { + String[] parts1 = parseServiceURI(serviceURI); + String[] parts2 = parseStructuralURI(endpointURI); + for (int i = 0; i < parts1.length; i++) { + if (parts1[i] == null || parts1[i].equals(parts2[i])) { + continue; + } else { + return false; + } + } + return true; + } + + /** + * Parse the service URI into an array of names. The service URI is in one of the following formats: + *
    + *
  • componentName + *
  • componentName/serviceName + *
  • componentName/serviceName/bindingName + *
+ * @param serviceURI + * @return + */ + protected String[] parseServiceURI(String serviceURI) { + if (serviceURI.contains("#")) { + return parseStructuralURI(serviceURI); + } + String[] names = new String[3]; + String[] segments = serviceURI.split("/"); + for (int i = 0; i < names.length && i < segments.length; i++) { + names[i] = segments[i]; + } + return names; + } + + /** + * Parse the structural URI into an array of parts (componentURI, serviceName, bindingName) + * @param structuralURI + * @return [0]: componentURI [1]: serviceName [2]: bindingName + */ + protected String[] parseStructuralURI(String structuralURI) { + String[] names = new String[3]; + int index = structuralURI.lastIndexOf('#'); + if (index == -1) { + names[0] = structuralURI; + } else { + names[0] = structuralURI.substring(0, index); + String str = structuralURI.substring(index + 1); + if (str.startsWith("service-binding(") && str.endsWith(")")) { + str = str.substring("service-binding(".length(), str.length() - 1); + String[] parts = str.split("/"); + if (parts.length != 2) { + throw new IllegalArgumentException("Invalid service-binding URI: " + structuralURI); + } + names[1] = parts[0]; + names[2] = parts[1]; + } else if (str.startsWith("service(") && str.endsWith(")")) { + str = str.substring("service(".length(), str.length() - 1); + names[1] = str; + } else { + throw new IllegalArgumentException("Invalid structural URI: " + structuralURI); + } + } + return names; + } + + public abstract void removeEndpoint(Endpoint endpoint); + + public void removeEndpointReference(EndpointReference endpointReference) { + endpointreferences.remove(endpointReference); + logger.fine("Remove endpoint reference - " + endpointReference); + } + + public void removeListener(EndpointListener listener) { + listeners.remove(listener); + } + +} diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultDomainRegistryFactoryExtensionPoint.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultDomainRegistryFactoryExtensionPoint.java new file mode 100644 index 0000000000..600ebb7bce --- /dev/null +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultDomainRegistryFactoryExtensionPoint.java @@ -0,0 +1,91 @@ +/* + * 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.runtime; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.LifeCycleListener; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceHelper; +import org.oasisopen.sca.ServiceRuntimeException; + +/** + * + */ +public class DefaultDomainRegistryFactoryExtensionPoint implements DomainRegistryFactoryExtensionPoint, + LifeCycleListener { + private ExtensionPointRegistry registry; + private boolean loaded; + private List factories = new ArrayList(); + + /** + * @param registry + */ + public DefaultDomainRegistryFactoryExtensionPoint(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + public void addDomainRegistryFactory(DomainRegistryFactory factory) { + ServiceHelper.start(factory); + factories.add(factory); + } + + public List getDomainRegistryFactories() { + load(); + return factories; + } + + private synchronized void load() { + if (loaded) { + return; + } + try { + Collection declarations = + registry.getServiceDiscovery().getServiceDeclarations(DomainRegistryFactory.class, true); + for (ServiceDeclaration declaration : declarations) { + DomainRegistryFactory factory = ServiceHelper.newInstance(registry, declaration); + addDomainRegistryFactory(factory); + } + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } finally { + loaded = true; + } + } + + public void removeDomainRegistryFactory(DomainRegistryFactory factory) { + if (factories.remove(factory)) { + ServiceHelper.stop(factory); + } + + } + + public void start() { + } + + public void stop() { + ServiceHelper.stop(factories); + } + +} diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactory.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactory.java index 7b71406ac6..bd97a525c0 100644 --- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactory.java +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactory.java @@ -20,7 +20,6 @@ package org.apache.tuscany.sca.runtime; import java.util.Collection; -import java.util.List; /** * @@ -42,5 +41,5 @@ public interface DomainRegistryFactory { Collection getEndpointRegistries(); void addListener(EndpointListener listener); void removeListener(EndpointListener listener); - List getListeners(); + String[] getSupportedSchemes(); } diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactoryExtensionPoint.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactoryExtensionPoint.java new file mode 100644 index 0000000000..4b823c0e7d --- /dev/null +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactoryExtensionPoint.java @@ -0,0 +1,33 @@ +/* + * 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.runtime; + +import java.util.List; + +/** + * + */ +public interface DomainRegistryFactoryExtensionPoint { + void addDomainRegistryFactory(DomainRegistryFactory factory); + + void removeDomainRegistryFactory(DomainRegistryFactory factory); + + List getDomainRegistryFactories(); +} diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java index 43cf9f6416..6c4839018d 100644 --- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.runtime; +import java.util.Collection; import java.util.List; import org.apache.tuscany.sca.assembly.Endpoint; @@ -28,22 +29,41 @@ import org.apache.tuscany.sca.assembly.EndpointReference; * The EndpointRegistry holds the active service endpoints for the SCA domain */ public interface EndpointRegistry { + /** + * Add an enpoint to the registry. If the endpoint URI is the same as an existing endpoint in the registry, + * the existing one will be updated + * @param endpoint + */ void addEndpoint(Endpoint endpoint); + + /** + * Remove an enpoint from the registry + * @param endpoint + */ void removeEndpoint(Endpoint endpoint); + /** + * Look up an enpoint from the registry + * @param uri The endpoint URI + * @return + */ Endpoint getEndpoint(String uri); - void updateEndpoint(String uri, Endpoint endpoint); + + /** + * Get all endpoints in the registry + * @return + */ + Collection getEndpoints(); + List findEndpoint(String uri); List findEndpoint(EndpointReference endpointReference); - List getEndpoints(); void addEndpointReference(EndpointReference endpointReference); void removeEndpointReference(EndpointReference endpointReference); - List findEndpointReference(Endpoint endpoint); + // List findEndpointReference(Endpoint endpoint); List getEndpointReferences(); void addListener(EndpointListener listener); void removeListener(EndpointListener listener); - List getListeners(); } diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ExtensibleDomainRegistry.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ExtensibleDomainRegistry.java new file mode 100644 index 0000000000..0a0b503206 --- /dev/null +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ExtensibleDomainRegistry.java @@ -0,0 +1,96 @@ +/* + * 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.runtime; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.oasisopen.sca.ServiceRuntimeException; + +/** + * + */ +public class ExtensibleDomainRegistry implements DomainRegistryFactory { + private final DomainRegistryFactoryExtensionPoint factories; + + public ExtensibleDomainRegistry(ExtensionPointRegistry registry) { + this.factories = registry.getExtensionPoint(DomainRegistryFactoryExtensionPoint.class); + } + + public ExtensibleDomainRegistry(DomainRegistryFactoryExtensionPoint factories) { + this.factories = factories; + } + + public void addListener(EndpointListener listener) { + for (DomainRegistryFactory factory : factories.getDomainRegistryFactories()) { + factory.addListener(listener); + } + } + + public Collection getEndpointRegistries() { + List registries = new ArrayList(); + for (DomainRegistryFactory factory : factories.getDomainRegistryFactories()) { + registries.addAll(factory.getEndpointRegistries()); + } + return registries; + } + + public EndpointRegistry getEndpointRegistry(String endpointRegistryURI, String domainURI) { + if (endpointRegistryURI == null) { + endpointRegistryURI = domainURI; + } + + URI uri = URI.create(endpointRegistryURI); + String scheme = uri.getScheme(); + if (scheme == null) { + scheme = "vm"; + endpointRegistryURI = "vm:" + endpointRegistryURI; + } else { + scheme = scheme.toLowerCase(); + } + for (DomainRegistryFactory factory : factories.getDomainRegistryFactories()) { + String[] schemes = factory.getSupportedSchemes(); + if (schemes != null && Arrays.asList(schemes).contains(scheme)) { + EndpointRegistry endpointRegistry = factory.getEndpointRegistry(endpointRegistryURI, domainURI); + if (endpointRegistry == null) { + continue; + } else { + return endpointRegistry; + } + } + } + throw new ServiceRuntimeException("No EndpointRegistry can support " + endpointRegistryURI); + } + + public void removeListener(EndpointListener listener) { + for (DomainRegistryFactory factory : factories.getDomainRegistryFactories()) { + factory.removeListener(listener); + } + } + + public String[] getSupportedSchemes() { + return null; + } + +} diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactoryExtensionPoint b/sca-java-2.x/trunk/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactoryExtensionPoint new file mode 100644 index 0000000000..be585a1e03 --- /dev/null +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactoryExtensionPoint @@ -0,0 +1,17 @@ +# 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. +org.apache.tuscany.sca.runtime.DefaultDomainRegistryFactoryExtensionPoint \ No newline at end of file diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointRegistryImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointRegistryImpl.java index 4fc2ffdd30..8c9e3f0951 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointRegistryImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointRegistryImpl.java @@ -25,23 +25,22 @@ import java.util.List; import java.util.logging.Logger; 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.LifeCycleListener; +import org.apache.tuscany.sca.runtime.BaseEndpointRegistry; import org.apache.tuscany.sca.runtime.EndpointListener; import org.apache.tuscany.sca.runtime.EndpointRegistry; /** * A EndpointRegistry implementation that sees registrations from the same JVM */ -public class EndpointRegistryImpl implements EndpointRegistry, LifeCycleListener { +public class EndpointRegistryImpl extends BaseEndpointRegistry implements EndpointRegistry, LifeCycleListener { private final Logger logger = Logger.getLogger(EndpointRegistryImpl.class.getName()); private List endpoints = new ArrayList(); - private List endpointreferences = new ArrayList(); - private List listeners = new ArrayList(); public EndpointRegistryImpl(ExtensionPointRegistry extensionPoints, String endpointRegistryURI, String domainURI) { + super(extensionPoints, null, endpointRegistryURI, domainURI); } public synchronized void addEndpoint(Endpoint endpoint) { @@ -52,69 +51,6 @@ public class EndpointRegistryImpl implements EndpointRegistry, LifeCycleListener logger.info("Add endpoint - " + endpoint.toString()); } - public synchronized void addEndpointReference(EndpointReference endpointReference) { - endpointreferences.add(endpointReference); - logger.fine("Add endpoint reference - " + endpointReference.toString()); - } - - /** - * Parse the component/service/binding URI into an array of parts (componentURI, serviceName, bindingName) - * @param uri - * @return - */ - private String[] parse(String uri) { - String[] names = new String[3]; - int index = uri.lastIndexOf('#'); - if (index == -1) { - names[0] = uri; - } else { - names[0] = uri.substring(0, index); - String str = uri.substring(index + 1); - if (str.startsWith("service-binding(") && str.endsWith(")")) { - str = str.substring("service-binding(".length(), str.length() - 1); - String[] parts = str.split("/"); - if (parts.length != 2) { - throw new IllegalArgumentException("Invalid service-binding URI: " + uri); - } - names[1] = parts[0]; - names[2] = parts[1]; - } else if (str.startsWith("service(") && str.endsWith(")")) { - str = str.substring("service(".length(), str.length() - 1); - names[1] = str; - } else { - throw new IllegalArgumentException("Invalid component/service/binding URI: " + uri); - } - } - return names; - } - - private boolean matches(String target, String uri) { - String[] parts1 = parse(target); - String[] parts2 = parse(uri); - for (int i = 0; i < parts1.length; i++) { - if (parts1[i] == null || parts1[i].equals(parts2[i])) { - continue; - } else { - return false; - } - } - return true; - } - - public synchronized List findEndpoint(EndpointReference endpointReference) { - List foundEndpoints = new ArrayList(); - - logger.fine("Find endpoint for reference - " + endpointReference.toString()); - - if (endpointReference.getReference() != null && - endpointReference.getTargetEndpoint() != null) { - Endpoint targetEndpoint = endpointReference.getTargetEndpoint(); - foundEndpoints.addAll(findEndpoint(targetEndpoint.getURI())); - } - - return foundEndpoints; - } - public List findEndpoint(String uri) { List foundEndpoints = new ArrayList(); for (Endpoint endpoint : endpoints) { @@ -127,48 +63,15 @@ public class EndpointRegistryImpl implements EndpointRegistry, LifeCycleListener return foundEndpoints; } - - public synchronized List findEndpointReference(Endpoint endpoint) { - return null; - } - public synchronized void removeEndpoint(Endpoint endpoint) { endpoints.remove(endpoint); endpointRemoved(endpoint); } - private void endpointRemoved(Endpoint endpoint) { - for (EndpointListener listener : listeners) { - listener.endpointRemoved(endpoint); - } - logger.info("Remove endpoint - " + endpoint.toString()); - } - - public synchronized void removeEndpointReference(EndpointReference endpointReference) { - endpointreferences.remove(endpointReference); - logger.fine("Remove endpoint reference - " + endpointReference.toString()); - } - - public synchronized List getEndpointReferences() { - return endpointreferences; - } - public synchronized List getEndpoints() { return endpoints; } - public synchronized void addListener(EndpointListener listener) { - listeners.add(listener); - } - - public synchronized List getListeners() { - return listeners; - } - - public synchronized void removeListener(EndpointListener listener) { - listeners.remove(listener); - } - public synchronized Endpoint getEndpoint(String uri) { for (Endpoint ep : endpoints) { String epURI = diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/LocalDomainRegistryFactory.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/LocalDomainRegistryFactory.java new file mode 100644 index 0000000000..b7d83e754a --- /dev/null +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/LocalDomainRegistryFactory.java @@ -0,0 +1,49 @@ +/* + * 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.core.assembly.impl; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.runtime.BaseDomainRegistryFactory; +import org.apache.tuscany.sca.runtime.EndpointRegistry; + +/** + * The utility responsible for finding the endpoint regstry by the scheme and creating instances for the + * given domain + */ +public class LocalDomainRegistryFactory extends BaseDomainRegistryFactory { + private final static String[] schemes = new String[] {"local", "vm"}; + + /** + * @param extensionRegistry + */ + public LocalDomainRegistryFactory(ExtensionPointRegistry registry) { + super(registry); + } + + protected EndpointRegistry createEndpointRegistry(String endpointRegistryURI, String domainURI) { + EndpointRegistry endpointRegistry = + new EndpointRegistryImpl(registry, endpointRegistryURI, domainURI); + return endpointRegistry; + } + + public String[] getSupportedSchemes() { + return schemes; + } +} diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/DefaultDomainRegistryFactory.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/DefaultDomainRegistryFactory.java deleted file mode 100644 index 784eca90ab..0000000000 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/DefaultDomainRegistryFactory.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * 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.core.runtime; - -import java.io.IOException; -import java.lang.reflect.Constructor; -import java.net.URI; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.LifeCycleListener; -import org.apache.tuscany.sca.extensibility.ServiceDeclaration; -import org.apache.tuscany.sca.runtime.DomainRegistryFactory; -import org.apache.tuscany.sca.runtime.EndpointListener; -import org.apache.tuscany.sca.runtime.EndpointRegistry; - -/** - * The utility responsible for finding the endpoint regstry by the scheme and creating instances for the - * given domain - */ -public class DefaultDomainRegistryFactory implements DomainRegistryFactory, LifeCycleListener { - private ExtensionPointRegistry extensionRegistry; - private Map declarations = new HashMap(); - private Map endpointRegistries = new ConcurrentHashMap(); - private List listeners = new ArrayList(); - - /** - * @param extensionRegistry - */ - public DefaultDomainRegistryFactory(ExtensionPointRegistry extensionRegistry) { - super(); - this.extensionRegistry = extensionRegistry; - } - - public void start() { - Collection sds = null; - try { - sds = extensionRegistry.getServiceDiscovery().getServiceDeclarations(EndpointRegistry.class); - } catch (IOException e) { - throw new IllegalStateException(e); - } - for (ServiceDeclaration sd : sds) { - String scheme = sd.getAttributes().get("scheme"); - if (scheme != null) { - scheme = scheme.toLowerCase(); - } - declarations.put(scheme, sd); - } - } - - public synchronized EndpointRegistry getEndpointRegistry(String endpointRegistryURI, String domainURI) { - if (endpointRegistryURI == null) { - endpointRegistryURI = domainURI; - } - - String key; - if (endpointRegistryURI.startsWith("tuscany:") || endpointRegistryURI.startsWith("tuscanyclient:")){ - key = "tuscany:," + domainURI; - } else { - key = endpointRegistryURI + "," + domainURI; - } - - EndpointRegistry endpointRegistry = endpointRegistries.get(key); - if (endpointRegistry != null) { - return endpointRegistry; - } - - // see if its a tuscany: one (TODO: need to clean all this up) - endpointRegistry = endpointRegistries.get("tuscany:," + domainURI); - if (endpointRegistry != null) { - return endpointRegistry; - } - // see if its a tuscany: one (TODO: need to clean all this up) - endpointRegistry = endpointRegistries.get(domainURI + "," + domainURI); - if (endpointRegistry != null) { - return endpointRegistry; - } - - String scheme = "tuscanyclient:".equals(endpointRegistryURI) ? "tuscanyClient" : URI.create(endpointRegistryURI).getScheme(); - if (scheme != null) { - scheme = scheme.toLowerCase(); - } else { - scheme = "vm"; - } - - ServiceDeclaration sd = declarations.get(scheme); - - try { - Class implClass = sd.loadClass(); - Constructor constructor = null; - try { - constructor = implClass.getConstructor(ExtensionPointRegistry.class, String.class, String.class); - endpointRegistry = - (EndpointRegistry)constructor.newInstance(extensionRegistry, endpointRegistryURI, domainURI); - } catch (NoSuchMethodException e) { - constructor = - implClass.getConstructor(ExtensionPointRegistry.class, Map.class, String.class, String.class); - endpointRegistry = - (EndpointRegistry)constructor.newInstance(extensionRegistry, - sd.getAttributes(), - endpointRegistryURI, - domainURI); - } - } catch (Exception e) { - throw new IllegalStateException(e); - } - - if (endpointRegistry instanceof LifeCycleListener) { - ((LifeCycleListener)endpointRegistry).start(); - } - - for (EndpointListener listener : listeners) { - endpointRegistry.addListener(listener); - } - if (!"tuscanyclient:".equals(endpointRegistryURI)) { - endpointRegistries.put(key, endpointRegistry); - } - return endpointRegistry; - } - - public void stop() { - declarations.clear(); - for (EndpointRegistry endpointRegistry : endpointRegistries.values()) { - if (endpointRegistry instanceof LifeCycleListener) { - ((LifeCycleListener)endpointRegistry).stop(); - } - } - endpointRegistries.clear(); - listeners.clear(); - } - - public synchronized Collection getEndpointRegistries() { - return new ArrayList(endpointRegistries.values()); - } - - public synchronized void addListener(EndpointListener listener) { - listeners.add(listener); - for(EndpointRegistry registry: endpointRegistries.values()) { - registry.addListener(listener); - } - } - - public synchronized List getListeners() { - return listeners; - } - - public synchronized void removeListener(EndpointListener listener) { - listeners.remove(listener); - for(EndpointRegistry registry: endpointRegistries.values()) { - registry.removeListener(listener); - } - } -} diff --git a/sca-java-2.x/trunk/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory b/sca-java-2.x/trunk/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory index c5c7e543ac..f2a6f0b4c3 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory +++ b/sca-java-2.x/trunk/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory @@ -5,14 +5,13 @@ # 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. -org.apache.tuscany.sca.core.runtime.DefaultDomainRegistryFactory - +# under the License. +org.apache.tuscany.sca.core.assembly.impl.LocalDomainRegistryFactory diff --git a/sca-java-2.x/trunk/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry b/sca-java-2.x/trunk/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry deleted file mode 100644 index 9ca8971396..0000000000 --- a/sca-java-2.x/trunk/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry +++ /dev/null @@ -1,18 +0,0 @@ -# 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. - -org.apache.tuscany.sca.core.assembly.impl.EndpointRegistryImpl;ranking=100,scheme=vm diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/domain/node/DomainNode.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/domain/node/DomainNode.java index 98f6b5a481..a1f5550ab0 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/domain/node/DomainNode.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/domain/node/DomainNode.java @@ -27,13 +27,13 @@ import java.util.Map; 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.configuration.NodeConfiguration; import org.apache.tuscany.sca.node.impl.NodeImpl; import org.apache.tuscany.sca.runtime.DomainRegistryFactory; import org.apache.tuscany.sca.runtime.EndpointRegistry; +import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistry; import org.oasisopen.sca.NoSuchDomainException; import org.oasisopen.sca.NoSuchServiceException; import org.oasisopen.sca.client.SCAClientFactory; @@ -116,8 +116,7 @@ public class DomainNode { List serviceNames = new ArrayList(); if (nodes.size() > 0) { ExtensionPointRegistry extensionsRegistry = ((NodeImpl)nodes.values().iterator().next()).getExtensionPoints(); - UtilityExtensionPoint utilities = extensionsRegistry.getExtensionPoint(UtilityExtensionPoint.class); - DomainRegistryFactory domainRegistryFactory = utilities.getUtility(DomainRegistryFactory.class); + DomainRegistryFactory domainRegistryFactory = new ExtensibleDomainRegistry(extensionsRegistry); EndpointRegistry endpointRegistry = domainRegistryFactory.getEndpointRegistry(getDomainConfigURI(), getDomainName()); for (Endpoint endpoint : endpointRegistry.getEndpoints()) { // Would be nice if Endpoint.getURI() returned this: diff --git a/sca-java-2.x/trunk/modules/endpoint-dht/src/main/java/org/apache/tuscany/sca/endpoint/dht/DHTDomainRegistryFactory.java b/sca-java-2.x/trunk/modules/endpoint-dht/src/main/java/org/apache/tuscany/sca/endpoint/dht/DHTDomainRegistryFactory.java new file mode 100644 index 0000000000..31ed20ad6f --- /dev/null +++ b/sca-java-2.x/trunk/modules/endpoint-dht/src/main/java/org/apache/tuscany/sca/endpoint/dht/DHTDomainRegistryFactory.java @@ -0,0 +1,51 @@ +/* + * 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.endpoint.dht; + +import java.util.HashMap; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.runtime.BaseDomainRegistryFactory; +import org.apache.tuscany.sca.runtime.EndpointRegistry; + +/** + * The utility responsible for finding the endpoint regstry by the scheme and creating instances for the + * given domain + */ +public class DHTDomainRegistryFactory extends BaseDomainRegistryFactory { + private final static String[] schemes = new String[] {"multicast", "tribes"}; + + /** + * @param extensionRegistry + */ + public DHTDomainRegistryFactory(ExtensionPointRegistry registry) { + super(registry); + } + + protected EndpointRegistry createEndpointRegistry(String endpointRegistryURI, String domainURI) { + EndpointRegistry endpointRegistry = + new OverlayEndpointRegistry(registry, new HashMap()); + return endpointRegistry; + } + + public String[] getSupportedSchemes() { + return schemes; + } +} diff --git a/sca-java-2.x/trunk/modules/endpoint-dht/src/main/java/org/apache/tuscany/sca/endpoint/dht/OverlayEndpointRegistry.java b/sca-java-2.x/trunk/modules/endpoint-dht/src/main/java/org/apache/tuscany/sca/endpoint/dht/OverlayEndpointRegistry.java index b8b582532a..1622143376 100644 --- a/sca-java-2.x/trunk/modules/endpoint-dht/src/main/java/org/apache/tuscany/sca/endpoint/dht/OverlayEndpointRegistry.java +++ b/sca-java-2.x/trunk/modules/endpoint-dht/src/main/java/org/apache/tuscany/sca/endpoint/dht/OverlayEndpointRegistry.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.ArrayList; +import java.util.Collection; import java.util.Enumeration; import java.util.List; import java.util.Map; @@ -258,7 +259,7 @@ public class OverlayEndpointRegistry implements EndpointRegistry, LifeCycleListe return endpointreferences; } - public List getEndpoints() { + public Collection getEndpoints() { /*TODO*/ return null; } diff --git a/sca-java-2.x/trunk/modules/endpoint-dht/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory b/sca-java-2.x/trunk/modules/endpoint-dht/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory new file mode 100644 index 0000000000..854c38a874 --- /dev/null +++ b/sca-java-2.x/trunk/modules/endpoint-dht/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory @@ -0,0 +1,17 @@ +# 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. +org.apache.tuscany.sca.endpoint.dht.DHTDomainRegistryFactory;ranking=20 diff --git a/sca-java-2.x/trunk/modules/endpoint-dht/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry b/sca-java-2.x/trunk/modules/endpoint-dht/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry deleted file mode 100644 index 0836d07fd1..0000000000 --- a/sca-java-2.x/trunk/modules/endpoint-dht/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry +++ /dev/null @@ -1,18 +0,0 @@ -# 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. -org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpointRegistry;ranking=150,address=planetlab2.fem.tu-ilmenau.de,port=3998,timeout=50 - diff --git a/sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/client/HazelcastClientDomainRegistryFactory.java b/sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/client/HazelcastClientDomainRegistryFactory.java new file mode 100644 index 0000000000..ad4d6d9e64 --- /dev/null +++ b/sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/client/HazelcastClientDomainRegistryFactory.java @@ -0,0 +1,49 @@ +/* + * 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.endpoint.hazelcast.client; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.runtime.BaseDomainRegistryFactory; +import org.apache.tuscany.sca.runtime.EndpointRegistry; + +/** + * The utility responsible for finding the endpoint regstry by the scheme and creating instances for the + * given domain + */ +public class HazelcastClientDomainRegistryFactory extends BaseDomainRegistryFactory { + private final static String[] schemes = new String[] {"hazelcastclient", "tuscanyclient"}; + + /** + * @param extensionRegistry + */ + public HazelcastClientDomainRegistryFactory(ExtensionPointRegistry registry) { + super(registry); + } + + protected EndpointRegistry createEndpointRegistry(String endpointRegistryURI, String domainURI) { + EndpointRegistry endpointRegistry = + new HazelcastClientEndpointRegistry(registry, null, endpointRegistryURI, domainURI); + return endpointRegistry; + } + + public String[] getSupportedSchemes() { + return schemes; + } +} diff --git a/sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory b/sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory new file mode 100644 index 0000000000..b15ea6a58f --- /dev/null +++ b/sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory @@ -0,0 +1,17 @@ +# 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. +org.apache.tuscany.sca.endpoint.hazelcast.client.HazelcastClientDomainRegistryFactory;ranking=100 diff --git a/sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry b/sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry deleted file mode 100644 index 5f8e2060f9..0000000000 --- a/sca-java-2.x/trunk/modules/endpoint-hazelcast-client/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry +++ /dev/null @@ -1,18 +0,0 @@ -# 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. -org.apache.tuscany.sca.endpoint.hazelcast.client.HazelcastClientEndpointRegistry;ranking=150,scheme=tuscanyclient - diff --git a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastDomainRegistryFactory.java b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastDomainRegistryFactory.java new file mode 100644 index 0000000000..a4e2da8be3 --- /dev/null +++ b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastDomainRegistryFactory.java @@ -0,0 +1,49 @@ +/* + * 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.endpoint.hazelcast; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.runtime.BaseDomainRegistryFactory; +import org.apache.tuscany.sca.runtime.EndpointRegistry; + +/** + * The utility responsible for finding the endpoint regstry by the scheme and creating instances for the + * given domain + */ +public class HazelcastDomainRegistryFactory extends BaseDomainRegistryFactory { + private final static String[] schemes = new String[] {"multicast", "wka", "tuscany", "hazelcast"}; + + /** + * @param extensionRegistry + */ + public HazelcastDomainRegistryFactory(ExtensionPointRegistry registry) { + super(registry); + } + + protected EndpointRegistry createEndpointRegistry(String endpointRegistryURI, String domainURI) { + EndpointRegistry endpointRegistry = + new HazelcastEndpointRegistry(registry, null, endpointRegistryURI, domainURI); + return endpointRegistry; + } + + public String[] getSupportedSchemes() { + return schemes; + } +} diff --git a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java index 7722a157f0..e50f0511cf 100644 --- a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java +++ b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java @@ -24,14 +24,12 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.CopyOnWriteArrayList; import java.util.logging.Logger; 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.LifeCycleListener; -import org.apache.tuscany.sca.runtime.EndpointListener; +import org.apache.tuscany.sca.runtime.BaseEndpointRegistry; import org.apache.tuscany.sca.runtime.EndpointRegistry; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; @@ -50,24 +48,20 @@ import com.hazelcast.nio.Address; /** * An EndpointRegistry using a Hazelcast */ -public class HazelcastEndpointRegistry implements EndpointRegistry, LifeCycleListener, EntryListener, MembershipListener { +public class HazelcastEndpointRegistry extends BaseEndpointRegistry implements EndpointRegistry, LifeCycleListener, EntryListener, MembershipListener { private final static Logger logger = Logger.getLogger(HazelcastEndpointRegistry.class.getName()); - private List endpointreferences = new CopyOnWriteArrayList(); - private List listeners = new CopyOnWriteArrayList(); - - private ExtensionPointRegistry registry; protected ConfigURI configURI; private HazelcastInstance hazelcastInstance; protected Map map; - private List localEndpoints = new ArrayList();; + private List localEndpoints = new ArrayList(); public HazelcastEndpointRegistry(ExtensionPointRegistry registry, Map attributes, String domainRegistryURI, String domainURI) { - this.registry = registry; + super(registry, attributes, domainRegistryURI, domainURI); this.configURI = new ConfigURI(domainRegistryURI); } @@ -143,68 +137,6 @@ public class HazelcastEndpointRegistry implements EndpointRegistry, LifeCycleLis logger.info("Add endpoint - " + endpoint); } - public void addEndpointReference(EndpointReference endpointReference) { - endpointreferences.add(endpointReference); - logger.fine("Add endpoint reference - " + endpointReference); - } - - public void addListener(EndpointListener listener) { - listeners.add(listener); - } - - /** - * Parse the component/service/binding URI into an array of parts (componentURI, serviceName, bindingName) - * @param uri - * @return - */ - private String[] parse(String uri) { - String[] names = new String[3]; - int index = uri.lastIndexOf('#'); - if (index == -1) { - names[0] = uri; - } else { - names[0] = uri.substring(0, index); - String str = uri.substring(index + 1); - if (str.startsWith("service-binding(") && str.endsWith(")")) { - str = str.substring("service-binding(".length(), str.length() - 1); - String[] parts = str.split("/"); - if (parts.length != 2) { - throw new IllegalArgumentException("Invalid service-binding URI: " + uri); - } - names[1] = parts[0]; - names[2] = parts[1]; - } else if (str.startsWith("service(") && str.endsWith(")")) { - str = str.substring("service(".length(), str.length() - 1); - names[1] = str; - } else { - throw new IllegalArgumentException("Invalid component/service/binding URI: " + uri); - } - } - return names; - } - - private boolean matches(String target, String uri) { - String[] parts1 = parse(target); - String[] parts2 = parse(uri); - for (int i = 0; i < parts1.length; i++) { - if (parts1[i] == null || parts1[i].equals(parts2[i])) { - continue; - } else { - return false; - } - } - return true; - } - - public List findEndpoint(EndpointReference endpointReference) { - logger.fine("Find endpoint for reference - " + endpointReference); - if (endpointReference.getReference() != null) { - Endpoint targetEndpoint = endpointReference.getTargetEndpoint(); - return findEndpoint(targetEndpoint.getURI()); - } - return new ArrayList(); - } - public List findEndpoint(String uri) { List foundEndpoints = new ArrayList(); for (Object v : map.values()) { @@ -227,45 +159,20 @@ public class HazelcastEndpointRegistry implements EndpointRegistry, LifeCycleLis return localEndpoints.contains(endpoint.getURI()); } - public List findEndpointReference(Endpoint endpoint) { - return endpointreferences; - } - public Endpoint getEndpoint(String uri) { return (Endpoint)map.get(uri); } - public List getEndpointReferences() { - return endpointreferences; - } - public List getEndpoints() { return new ArrayList(map.values()); } - public List getListeners() { - return listeners; - } - public void removeEndpoint(Endpoint endpoint) { map.remove(endpoint.getURI()); localEndpoints.remove(endpoint.getURI()); logger.info("Removed endpoint - " + endpoint); } - public void removeEndpointReference(EndpointReference endpointReference) { - endpointreferences.remove(endpointReference); - logger.fine("Remove endpoint reference - " + endpointReference); - } - - public void removeListener(EndpointListener listener) { - listeners.remove(listener); - } - - public void updateEndpoint(String uri, Endpoint endpoint) { - // // TODO: is updateEndpoint needed? - // throw new UnsupportedOperationException(); - } public void entryAdded(EntryEvent event) { entryAdded(event.getKey(), event.getValue()); @@ -289,10 +196,7 @@ public class HazelcastEndpointRegistry implements EndpointRegistry, LifeCycleLis logger.info(" Remote endpoint added: " + newEp); newEp.setRemote(true); } - ((RuntimeEndpoint)newEp).bind(registry, this); - for (EndpointListener listener : listeners) { - listener.endpointAdded(newEp); - } + endpointAdded(newEp); } public void entryRemoved(Object key, Object value) { @@ -300,10 +204,7 @@ public class HazelcastEndpointRegistry implements EndpointRegistry, LifeCycleLis if (!isLocal(oldEp)) { logger.info(" Remote endpoint removed: " + value); } - ((RuntimeEndpoint) oldEp).bind(registry, this); - for (EndpointListener listener : listeners) { - listener.endpointRemoved(oldEp); - } + endpointRemoved(oldEp); } public void entryUpdated(Object key, Object oldValue, Object newValue) { @@ -312,10 +213,7 @@ public class HazelcastEndpointRegistry implements EndpointRegistry, LifeCycleLis if (!isLocal(newEp)) { logger.info(" Remote endpoint updated: " + newEp); } - ((RuntimeEndpoint)newEp).bind(registry, this); - for (EndpointListener listener : listeners) { - listener.endpointUpdated(oldEp, newEp); - } + endpointUpdated(oldEp, newEp); } public void memberAdded(MembershipEvent event) { diff --git a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory new file mode 100644 index 0000000000..23551701a5 --- /dev/null +++ b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory @@ -0,0 +1,17 @@ +# 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. +org.apache.tuscany.sca.endpoint.hazelcast.HazelcastDomainRegistryFactory;ranking=100 diff --git a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry deleted file mode 100644 index 1983881ce1..0000000000 --- a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry +++ /dev/null @@ -1,18 +0,0 @@ -# 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. -org.apache.tuscany.sca.endpoint.hazelcast.HazelcastEndpointRegistry;ranking=150,scheme=tuscany - diff --git a/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java b/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java index fc16db7a74..3c2a062de2 100644 --- a/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java +++ b/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java @@ -31,8 +31,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; -import java.util.UUID; -import java.util.concurrent.CopyOnWriteArrayList; import java.util.logging.Level; import java.util.logging.Logger; @@ -46,23 +44,23 @@ import org.apache.catalina.tribes.membership.McastService; import org.apache.catalina.tribes.membership.StaticMember; import org.apache.catalina.tribes.transport.ReceiverBase; 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.LifeCycleListener; import org.apache.tuscany.sca.endpoint.tribes.AbstractReplicatedMap.MapEntry; import org.apache.tuscany.sca.endpoint.tribes.MapStore.MapListener; -import org.apache.tuscany.sca.runtime.EndpointListener; +import org.apache.tuscany.sca.runtime.BaseEndpointRegistry; import org.apache.tuscany.sca.runtime.EndpointRegistry; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; /** * A replicated EndpointRegistry based on Apache Tomcat Tribes */ -public class ReplicatedEndpointRegistry implements EndpointRegistry, LifeCycleListener, MapListener { +public class ReplicatedEndpointRegistry extends BaseEndpointRegistry implements EndpointRegistry, LifeCycleListener, + MapListener { private final static Logger logger = Logger.getLogger(ReplicatedEndpointRegistry.class.getName()); private static final String MULTICAST_ADDRESS = "228.0.0.100"; private static final int MULTICAST_PORT = 50000; - + private static final int FIND_REPEAT_COUNT = 10; private int port = MULTICAST_PORT; @@ -73,12 +71,6 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry, LifeCycleLi private int receiverAutoBind = 100; private List staticRoutes; - private final static String DEFAULT_DOMAIN_URI = "http://tuscany.apache.org/sca/1.1/domains/default"; - private String domainURI = DEFAULT_DOMAIN_URI; - private List endpointreferences = new CopyOnWriteArrayList(); - private List listeners = new CopyOnWriteArrayList(); - - private ExtensionPointRegistry registry; private ReplicatedMap map; private String id; @@ -101,7 +93,7 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry, LifeCycleLi } else { mcastService.setBind(getBindAddress()); } - + return channel; } @@ -109,9 +101,7 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry, LifeCycleLi Map attributes, String domainRegistryURI, String domainURI) { - this.registry = registry; - this.domainURI = domainURI; - this.id = "[" + System.identityHashCode(this) + "]"; + super(registry, attributes, domainRegistryURI, domainURI); getParameters(attributes, domainRegistryURI); } @@ -220,7 +210,7 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry, LifeCycleLi ((AbstractSender)sender).setMaxRetryAttempts(5); } */ - + if (staticRoutes != null) { StaticMembershipInterceptor smi = new StaticMembershipInterceptor(); for (URI staticRoute : staticRoutes) { @@ -237,7 +227,7 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry, LifeCycleLi smi.setLocalMember(map.getChannel().getLocalMember(false)); map.getChannel().addInterceptor(smi); } - + try { map.getChannel().start(Channel.DEFAULT); } catch (ChannelException e) { @@ -265,78 +255,14 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry, LifeCycleLi logger.info("Add endpoint - " + endpoint); } - public void addEndpointReference(EndpointReference endpointReference) { - endpointreferences.add(endpointReference); - logger.fine("Add endpoint reference - " + endpointReference); - } - - public void addListener(EndpointListener listener) { - listeners.add(listener); - } - - /** - * Parse the component/service/binding URI into an array of parts (componentURI, serviceName, bindingName) - * @param uri - * @return - */ - private String[] parse(String uri) { - String[] names = new String[3]; - int index = uri.lastIndexOf('#'); - if (index == -1) { - names[0] = uri; - } else { - names[0] = uri.substring(0, index); - String str = uri.substring(index + 1); - if (str.startsWith("service-binding(") && str.endsWith(")")) { - str = str.substring("service-binding(".length(), str.length() - 1); - String[] parts = str.split("/"); - if (parts.length != 2) { - throw new IllegalArgumentException("Invalid service-binding URI: " + uri); - } - names[1] = parts[0]; - names[2] = parts[1]; - } else if (str.startsWith("service(") && str.endsWith(")")) { - str = str.substring("service(".length(), str.length() - 1); - names[1] = str; - } else { - throw new IllegalArgumentException("Invalid component/service/binding URI: " + uri); - } - } - return names; - } - - private boolean matches(String target, String uri) { - String[] parts1 = parse(target); - String[] parts2 = parse(uri); - for (int i = 0; i < parts1.length; i++) { - if (parts1[i] == null || parts1[i].equals(parts2[i])) { - continue; - } else { - return false; - } - } - return true; - } - - public List findEndpoint(EndpointReference endpointReference) { - logger.fine("Find endpoint for reference - " + endpointReference); - - if (endpointReference.getReference() != null) { - Endpoint targetEndpoint = endpointReference.getTargetEndpoint(); - return findEndpoint(targetEndpoint.getURI()); - } - - return new ArrayList(); - } - public List findEndpoint(String uri) { List foundEndpoints = new ArrayList(); // 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){ + + while (repeat > 0) { for (Object v : map.values()) { Endpoint endpoint = (Endpoint)v; // TODO: implement more complete matching @@ -347,15 +273,15 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry, LifeCycleLi endpoint.setRemote(true); } // if (!entry.isPrimary()) { - ((RuntimeEndpoint) endpoint).bind(registry, this); + ((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 @@ -363,9 +289,9 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry, LifeCycleLi repeat--; try { Thread.sleep(1000); - } catch(Exception ex){ + } catch (Exception ex) { // do nothing - repeat=0; + repeat = 0; } } } @@ -373,45 +299,23 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry, LifeCycleLi return foundEndpoints; } - private boolean isLocal(MapEntry entry) { return entry.getPrimary().equals(map.getChannel().getLocalMember(false)); } - public List findEndpointReference(Endpoint endpoint) { - return endpointreferences; - } - public Endpoint getEndpoint(String uri) { return (Endpoint)map.get(uri); } - public List getEndpointReferences() { - return endpointreferences; - } - public List getEndpoints() { return new ArrayList(map.values()); } - public List getListeners() { - return listeners; - } - public void removeEndpoint(Endpoint endpoint) { map.remove(endpoint.getURI()); logger.info("Remove endpoint - " + endpoint); } - public void removeEndpointReference(EndpointReference endpointReference) { - endpointreferences.remove(endpointReference); - logger.fine("Remove endpoint reference - " + endpointReference); - } - - public void removeListener(EndpointListener listener) { - listeners.remove(listener); - } - public void replicate(boolean complete) { map.replicate(complete); } @@ -431,10 +335,7 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry, LifeCycleLi logger.info(id + " Remote endpoint added: " + entry.getValue()); newEp.setRemote(true); } - ((RuntimeEndpoint) newEp).bind(registry, this); - for (EndpointListener listener : listeners) { - listener.endpointAdded(newEp); - } + endpointAdded(newEp); } public void entryRemoved(Object key, Object value) { @@ -442,11 +343,7 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry, LifeCycleLi if (!isLocal(entry)) { logger.info(id + " Remote endpoint removed: " + entry.getValue()); } - Endpoint oldEp = (Endpoint)entry.getValue(); - ((RuntimeEndpoint) oldEp).bind(registry, this); - for (EndpointListener listener : listeners) { - listener.endpointRemoved(oldEp); - } + endpointRemoved((Endpoint)entry.getValue()); } public void entryUpdated(Object key, Object oldValue, Object newValue) { @@ -457,46 +354,7 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry, LifeCycleLi } Endpoint oldEp = (Endpoint)oldEntry.getValue(); Endpoint newEp = (Endpoint)newEntry.getValue(); - ((RuntimeEndpoint) newEp).bind(registry, this); - for (EndpointListener listener : listeners) { - listener.endpointUpdated(oldEp, newEp); - } - } - - public static void main(String[] args) throws Exception { - //create a channel - GroupChannel channel = new GroupChannel(); - McastService mcastService = (McastService)channel.getMembershipService(); - mcastService.setPort(MULTICAST_PORT); - mcastService.setAddress(MULTICAST_ADDRESS); - - -// ChannelReceiver rcv = channel.getChannelReceiver(); -// ReceiverBase rcvb = (ReceiverBase)rcv; -// rcvb.setPort(10480); - - InetAddress localhost = InetAddress.getLocalHost(); - - // REVIEW: In my case, there are multiple IP addresses - // One for the WIFI and the other one for VPN. For some reason the VPN one doesn't support - // Multicast - - // You can use "route add 228.0.0.0 mask 252.0.0.0 192.168.1.100" - mcastService.setBind(getBindAddress()); - channel.start(Channel.DEFAULT); - ReplicatedMap map = new ReplicatedMap(null, channel, 50, "01", null); - map.put(UUID.randomUUID().toString(), localhost.getHostAddress()); - for (int i = 0; i < 4; i++) { - Thread.sleep(3000); - System.out.println(localhost + ": " + map.keySet()); - } - for (Object e : map.entrySetFull()) { - Map.Entry en = (Map.Entry)e; - AbstractReplicatedMap.MapEntry entry = (AbstractReplicatedMap.MapEntry)en.getValue(); - System.out.println(entry); - } - map.breakdown(); - channel.stop(Channel.DEFAULT); + endpointUpdated(oldEp, newEp); } private static String getBindAddress() { diff --git a/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/TribesDomainRegistryFactory.java b/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/TribesDomainRegistryFactory.java new file mode 100644 index 0000000000..68add08276 --- /dev/null +++ b/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/TribesDomainRegistryFactory.java @@ -0,0 +1,49 @@ +/* + * 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.endpoint.tribes; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.runtime.BaseDomainRegistryFactory; +import org.apache.tuscany.sca.runtime.EndpointRegistry; + +/** + * The utility responsible for finding the endpoint regstry by the scheme and creating instances for the + * given domain + */ +public class TribesDomainRegistryFactory extends BaseDomainRegistryFactory { + private final static String[] schemes = new String[] {"multicast", "tribes"}; + + /** + * @param extensionRegistry + */ + public TribesDomainRegistryFactory(ExtensionPointRegistry registry) { + super(registry); + } + + protected EndpointRegistry createEndpointRegistry(String endpointRegistryURI, String domainURI) { + EndpointRegistry endpointRegistry = + new ReplicatedEndpointRegistry(registry, null, endpointRegistryURI, domainURI); + return endpointRegistry; + } + + public String[] getSupportedSchemes() { + return schemes; + } +} diff --git a/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory b/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory new file mode 100644 index 0000000000..734afb2ac5 --- /dev/null +++ b/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory @@ -0,0 +1,17 @@ +# 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. +org.apache.tuscany.sca.endpoint.tribes.TribesDomainRegistryFactory;ranking=50 \ No newline at end of file diff --git a/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry b/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry deleted file mode 100644 index a16785beef..0000000000 --- a/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry +++ /dev/null @@ -1,17 +0,0 @@ -# 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. -org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpointRegistry;ranking=150,address=228.0.0.100,port=50000,timeout=50,scheme=tribes diff --git a/sca-java-2.x/trunk/modules/endpoint-zookeeper/src/main/java/org/apache/tuscany/sca/endpoint/zookeeper/DistributedRegistry.java b/sca-java-2.x/trunk/modules/endpoint-zookeeper/src/main/java/org/apache/tuscany/sca/endpoint/zookeeper/DistributedRegistry.java index 0e74bcb092..1a7f2bba79 100644 --- a/sca-java-2.x/trunk/modules/endpoint-zookeeper/src/main/java/org/apache/tuscany/sca/endpoint/zookeeper/DistributedRegistry.java +++ b/sca-java-2.x/trunk/modules/endpoint-zookeeper/src/main/java/org/apache/tuscany/sca/endpoint/zookeeper/DistributedRegistry.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -223,7 +224,7 @@ public class DistributedRegistry extends AbstractDistributedMap implem return endpointreferences; } - public List getEndpoints() { + public Collection getEndpoints() { return new ArrayList(values()); } diff --git a/sca-java-2.x/trunk/modules/endpoint-zookeeper/src/main/java/org/apache/tuscany/sca/endpoint/zookeeper/ZooKeeperDomainRegistryFactory.java b/sca-java-2.x/trunk/modules/endpoint-zookeeper/src/main/java/org/apache/tuscany/sca/endpoint/zookeeper/ZooKeeperDomainRegistryFactory.java new file mode 100644 index 0000000000..2f9dcfc27f --- /dev/null +++ b/sca-java-2.x/trunk/modules/endpoint-zookeeper/src/main/java/org/apache/tuscany/sca/endpoint/zookeeper/ZooKeeperDomainRegistryFactory.java @@ -0,0 +1,49 @@ +/* + * 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.endpoint.zookeeper; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.runtime.BaseDomainRegistryFactory; +import org.apache.tuscany.sca.runtime.EndpointRegistry; + +/** + * The utility responsible for finding the endpoint regstry by the scheme and creating instances for the + * given domain + */ +public class ZooKeeperDomainRegistryFactory extends BaseDomainRegistryFactory { + private final static String[] schemes = new String[] {"zookeeper"}; + + /** + * @param extensionRegistry + */ + public ZooKeeperDomainRegistryFactory(ExtensionPointRegistry registry) { + super(registry); + } + + protected EndpointRegistry createEndpointRegistry(String endpointRegistryURI, String domainURI) { + EndpointRegistry endpointRegistry = + new DistributedRegistry(registry, null, endpointRegistryURI, domainURI); + return endpointRegistry; + } + + public String[] getSupportedSchemes() { + return schemes; + } +} diff --git a/sca-java-2.x/trunk/modules/endpoint-zookeeper/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory b/sca-java-2.x/trunk/modules/endpoint-zookeeper/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory new file mode 100644 index 0000000000..42458b8910 --- /dev/null +++ b/sca-java-2.x/trunk/modules/endpoint-zookeeper/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory @@ -0,0 +1,17 @@ +# 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. +org.apache.tuscany.sca.endpoint.zookeeper.ZooKeeperDomainRegistryFactory;ranking=20 \ No newline at end of file diff --git a/sca-java-2.x/trunk/modules/endpoint-zookeeper/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry b/sca-java-2.x/trunk/modules/endpoint-zookeeper/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry deleted file mode 100644 index c17d8c35c5..0000000000 --- a/sca-java-2.x/trunk/modules/endpoint-zookeeper/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry +++ /dev/null @@ -1,17 +0,0 @@ -# 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. -org.apache.tuscany.sca.endpoint.zookeeper.DistributedRegistry;scheme=zookeeper diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java index c9c4cb6a69..c61e2f4ca6 100644 --- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java +++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java @@ -26,12 +26,12 @@ import java.util.Dictionary; import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.core.LifeCycleListener; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation; import org.apache.tuscany.sca.node.configuration.NodeConfiguration; import org.apache.tuscany.sca.runtime.DomainRegistryFactory; import org.apache.tuscany.sca.runtime.EndpointListener; import org.apache.tuscany.sca.runtime.EndpointRegistry; +import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistry; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.service.remoteserviceadmin.EndpointDescription; @@ -49,8 +49,7 @@ public class DomainDiscoveryService extends AbstractDiscoveryService implements public void start() { super.start(); - this.domainRegistryFactory = - registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(DomainRegistryFactory.class); + this.domainRegistryFactory = new ExtensibleDomainRegistry(registry); domainRegistryFactory.addListener(this); // [rfeng] Starting of the endpoint registry takes a long time and it leaves the bundle diff --git a/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java index 86da71b4b2..4f4c3ba123 100644 --- a/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java +++ b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java @@ -80,6 +80,7 @@ import org.apache.tuscany.sca.node.configuration.NodeConfiguration; import org.apache.tuscany.sca.runtime.DomainRegistryFactory; import org.apache.tuscany.sca.runtime.EndpointReferenceBinder; import org.apache.tuscany.sca.runtime.EndpointRegistry; +import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistry; import org.apache.tuscany.sca.work.WorkScheduler; import org.oasisopen.sca.ServiceRuntimeException; @@ -297,7 +298,7 @@ public class NodeFactoryImpl extends NodeFactory { // autowire which still relies on matching in the builder private void postBuildEndpointReferenceMatching(Composite composite){ EndpointReferenceBinder endpointReferenceBinder = registry.getExtensionPoint(EndpointReferenceBinder.class); - DomainRegistryFactory domainRegistryFactory = registry.getExtensionPoint(DomainRegistryFactory.class); + DomainRegistryFactory domainRegistryFactory = new ExtensibleDomainRegistry(registry); // create temporary local registry for all available local endpoints // TODO - need a better way of getting a local registry diff --git a/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java index 51073acfd1..483431b98a 100644 --- a/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java +++ b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java @@ -54,6 +54,7 @@ import org.apache.tuscany.sca.runtime.ActivationException; import org.apache.tuscany.sca.runtime.CompositeActivator; import org.apache.tuscany.sca.runtime.DomainRegistryFactory; import org.apache.tuscany.sca.runtime.EndpointRegistry; +import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistry; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentContext; import org.apache.tuscany.sca.runtime.RuntimeComponentService; @@ -112,13 +113,13 @@ public class NodeImpl implements Node, Client { manager.init(); manager.addNode(configuration, this); this.proxyFactory = manager.proxyFactory; - UtilityExtensionPoint utilities = manager.registry.getExtensionPoint(UtilityExtensionPoint.class); - DomainRegistryFactory domainRegistryFactory = utilities.getUtility(DomainRegistryFactory.class); + DomainRegistryFactory domainRegistryFactory = new ExtensibleDomainRegistry(manager.registry); EndpointRegistry endpointRegistry = domainRegistryFactory.getEndpointRegistry(configuration.getDomainRegistryURI(), configuration .getDomainURI()); - + + UtilityExtensionPoint utilities = manager.registry.getExtensionPoint(UtilityExtensionPoint.class); this.compositeActivator = utilities.getUtility(CompositeActivator.class); try { Monitor monitor = manager.monitorFactory.createMonitor(); @@ -370,8 +371,7 @@ public class NodeImpl implements Node, Client { public List getServiceNames() { List serviceNames = new ArrayList(); ExtensionPointRegistry extensionsRegistry = getExtensionPoints(); - UtilityExtensionPoint utilities = extensionsRegistry.getExtensionPoint(UtilityExtensionPoint.class); - DomainRegistryFactory domainRegistryFactory = utilities.getUtility(DomainRegistryFactory.class); + DomainRegistryFactory domainRegistryFactory = new ExtensibleDomainRegistry(extensionsRegistry); EndpointRegistry endpointRegistry = domainRegistryFactory.getEndpointRegistry(configuration.getDomainRegistryURI(), configuration.getDomainName()); for (Endpoint endpoint : endpointRegistry.getEndpoints()) { // Would be nice if Endpoint.getURI() returned this: 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 4b5e696d4f..1d6937364c 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 @@ -26,13 +26,13 @@ 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.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.apache.tuscany.sca.runtime.ExtensibleDomainRegistry; import org.oasisopen.sca.NoSuchDomainException; import org.oasisopen.sca.NoSuchServiceException; import org.oasisopen.sca.client.SCAClientFactory; @@ -53,8 +53,7 @@ public class SCAClientFactoryImpl extends SCAClientFactory { this.nodeFactory = (NodeFactoryImpl)NodeFactory.getInstance(); this.extensionsRegistry = nodeFactory.getExtensionPoints(); - UtilityExtensionPoint utilities = extensionsRegistry.getExtensionPoint(UtilityExtensionPoint.class); - DomainRegistryFactory domainRegistryFactory = utilities.getUtility(DomainRegistryFactory.class); + DomainRegistryFactory domainRegistryFactory = new ExtensibleDomainRegistry(extensionsRegistry); 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) diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator index 2c08ac72cf..97a05b05a4 100644 --- a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator +++ b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. # Implementation class for the ModuleActivator -org.apache.tuscany.sca.client.impl.SCAClientModuleActivator;priority=100 +org.apache.tuscany.sca.client.impl.SCAClientModuleActivator;ranking=100 diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/resources/META-INF/services/org.oasisopen.sca.client.SCAClientFactory b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/resources/META-INF/services/org.oasisopen.sca.client.SCAClientFactory index 3a90a22a85..5ac3eedff4 100644 --- a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/resources/META-INF/services/org.oasisopen.sca.client.SCAClientFactory +++ b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/resources/META-INF/services/org.oasisopen.sca.client.SCAClientFactory @@ -1,2 +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.impl.SCAClientFactoryImpl - 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 f949763e9b..7b83e49f0c 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 @@ -26,13 +26,13 @@ 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.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.apache.tuscany.sca.runtime.ExtensibleDomainRegistry; import org.oasisopen.sca.NoSuchDomainException; import org.oasisopen.sca.NoSuchServiceException; import org.oasisopen.sca.client.SCAClientFactory; @@ -54,9 +54,9 @@ public class SCAClientFactoryImpl extends SCAClientFactory { 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(getRegistryURI(), getDomainName()); + this.extensionsRegistry = nodeFactory.getExtensionPoints(); + DomainRegistryFactory domainRegistryFactory = new ExtensibleDomainRegistry(extensionsRegistry); + this.endpointRegistry = domainRegistryFactory.getEndpointRegistry(getRegistryURI(), getDomainName()); } } 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 b65f311da2..4648d7cdbe 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 @@ -30,7 +30,6 @@ 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; @@ -39,6 +38,7 @@ 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.apache.tuscany.sca.runtime.ExtensibleDomainRegistry; import org.oasisopen.sca.NoSuchServiceException; public class SCAClientProxyHandler implements InvocationHandler { @@ -75,8 +75,7 @@ public class SCAClientProxyHandler implements InvocationHandler { Endpoint targetEndpoint = assemblyFactory.createEndpoint(); targetEndpoint.setURI(serviceName); endpointReference.setTargetEndpoint(targetEndpoint); - UtilityExtensionPoint utilities = extensionsRegistry.getExtensionPoint(UtilityExtensionPoint.class); - DomainRegistryFactory domainRegistryFactory = utilities.getUtility(DomainRegistryFactory.class); + DomainRegistryFactory domainRegistryFactory = new ExtensibleDomainRegistry(extensionsRegistry); this.endpointRegistry = domainRegistryFactory.getEndpointRegistry(null, domainURI); List endpoints = endpointRegistry.findEndpoint(endpointReference); 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 index aef20a3d23..8ae7671239 100644 --- 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 @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. # Implementation class for the ModuleActivator -org.apache.tuscany.sca.client.rmi.SCAClientModuleActivator;priority=200 +org.apache.tuscany.sca.client.rmi.SCAClientModuleActivator;ranking=200 diff --git a/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/resources/META-INF/services/org.oasisopen.sca.client.SCAClientFactory b/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/resources/META-INF/services/org.oasisopen.sca.client.SCAClientFactory index d153c9bc02..8be1f22af4 100644 --- a/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/resources/META-INF/services/org.oasisopen.sca.client.SCAClientFactory +++ b/sca-java-2.x/trunk/modules/sca-client-rmi/src/main/resources/META-INF/services/org.oasisopen.sca.client.SCAClientFactory @@ -1,2 +1,19 @@ +# 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.SCAClientFactoryImpl -- cgit v1.2.3