diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/core')
5 files changed, 56 insertions, 298 deletions
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<Endpoint> endpoints = new ArrayList<Endpoint>(); - private List<EndpointReference> endpointreferences = new ArrayList<EndpointReference>(); - private List<EndpointListener> listeners = new ArrayList<EndpointListener>(); 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<Endpoint> findEndpoint(EndpointReference endpointReference) { - List<Endpoint> foundEndpoints = new ArrayList<Endpoint>(); - - 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<Endpoint> findEndpoint(String uri) { List<Endpoint> foundEndpoints = new ArrayList<Endpoint>(); for (Endpoint endpoint : endpoints) { @@ -127,48 +63,15 @@ public class EndpointRegistryImpl implements EndpointRegistry, LifeCycleListener return foundEndpoints; } - - public synchronized List<EndpointReference> 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<EndpointReference> getEndpointReferences() { - return endpointreferences; - } - public synchronized List<Endpoint> getEndpoints() { return endpoints; } - public synchronized void addListener(EndpointListener listener) { - listeners.add(listener); - } - - public synchronized List<EndpointListener> 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<String, ServiceDeclaration> declarations = new HashMap<String, ServiceDeclaration>(); - private Map<String, EndpointRegistry> endpointRegistries = new ConcurrentHashMap<String, EndpointRegistry>(); - private List<EndpointListener> listeners = new ArrayList<EndpointListener>(); - - /** - * @param extensionRegistry - */ - public DefaultDomainRegistryFactory(ExtensionPointRegistry extensionRegistry) { - super(); - this.extensionRegistry = extensionRegistry; - } - - public void start() { - Collection<ServiceDeclaration> 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<EndpointRegistry> getEndpointRegistries() { - return new ArrayList<EndpointRegistry>(endpointRegistries.values()); - } - - public synchronized void addListener(EndpointListener listener) { - listeners.add(listener); - for(EndpointRegistry registry: endpointRegistries.values()) { - registry.addListener(listener); - } - } - - public synchronized List<EndpointListener> 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
|