diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-09 19:59:43 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-09 19:59:43 +0000 |
commit | 681e195552e16021ebba42fcf56bad2aa6fddc67 (patch) | |
tree | 156e2714fa1584ff3e3a989359b78b51f2ff78ea /java/sca/modules/core/src/main | |
parent | e2a82e1954ef1ac97c26d4f6bca4184494b541b9 (diff) |
Refactor the runtime build logic into EndpointReferenceBinder
Refactor the endpoint-wrapper into domainRegistryFactory that delegates to endpoint registry implementations by the scheme
Improve/workaround the monitor so that it can be shared by multiple nodes (We need a better design for this)
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@823672 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/core/src/main')
9 files changed, 300 insertions, 166 deletions
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java index de9b575926..1c4ded13fc 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java @@ -100,13 +100,13 @@ public class CompositeActivatorImpl implements CompositeActivator { // Composite activation/deactivation - public void activate(Composite composite) throws ActivationException { + public void activate(CompositeContext compositeContext, Composite composite) throws ActivationException { try { if (logger.isLoggable(Level.FINE)) { logger.fine("Activating composite: " + composite.getName()); } for (Component component : composite.getComponents()) { - activateComponent(component); + activateComponent(compositeContext, component); } } catch (Exception e) { throw new ActivationException(e); @@ -128,7 +128,7 @@ public class CompositeActivatorImpl implements CompositeActivator { // Component activation/deactivation - public void activateComponent(Component component) + public void activateComponent(CompositeContext compositeContext, Component component) throws ActivationException { try { if (logger.isLoggable(Level.FINE)) { @@ -137,7 +137,7 @@ public class CompositeActivatorImpl implements CompositeActivator { Implementation implementation = component.getImplementation(); if (implementation instanceof Composite) { - activate((Composite) implementation); + activate(compositeContext, (Composite) implementation); } else if (implementation != null) { addImplementationProvider((RuntimeComponent) component, implementation); @@ -145,13 +145,13 @@ public class CompositeActivatorImpl implements CompositeActivator { } for (ComponentService service : component.getServices()) { - activate((RuntimeComponent) component, - (RuntimeComponentService) service); + activate(compositeContext, + (RuntimeComponent) component, (RuntimeComponentService) service); } for (ComponentReference reference : component.getReferences()) { - activate((RuntimeComponent) component, - (RuntimeComponentReference) reference); + activate(compositeContext, + (RuntimeComponent) component, (RuntimeComponentReference) reference); } } catch (Exception e) { throw new ActivationException(e); @@ -237,7 +237,7 @@ public class CompositeActivatorImpl implements CompositeActivator { // Service activation/deactivation - public void activate(RuntimeComponent component, RuntimeComponentService service) { + public void activate(CompositeContext compositeContext, RuntimeComponent component, RuntimeComponentService service) { if (service.getService() == null) { if (logger.isLoggable(Level.WARNING)) { logger.warning("Skipping component service not defined in the component type: " + component.getURI() @@ -261,7 +261,7 @@ public class CompositeActivatorImpl implements CompositeActivator { for (Endpoint endpoint : service.getEndpoints()) { addServiceBindingProvider(endpoint, component, service, endpoint.getBinding()); } - addServiceWires(component, service); + addServiceWires(compositeContext, component, service); } public void deactivate(RuntimeComponent component, RuntimeComponentService service) { @@ -313,7 +313,7 @@ public class CompositeActivatorImpl implements CompositeActivator { } } - private void addServiceWires(Component serviceComponent, ComponentService service) { + private void addServiceWires(CompositeContext compositeContext, Component serviceComponent, ComponentService service) { if (!(service instanceof RuntimeComponentService)) { return; } @@ -341,7 +341,7 @@ public class CompositeActivatorImpl implements CompositeActivator { endpointReference.setInterfaceContract(getServiceBindingInterfaceContract(service, endpoint.getBinding())); // create the wire - RuntimeWire wire = new RuntimeWireImpl(extensionPoints, + RuntimeWire wire = new RuntimeWireImpl(compositeContext, false, endpointReference, endpoint, @@ -381,7 +381,7 @@ public class CompositeActivatorImpl implements CompositeActivator { // Reference activation/deactivation - public void activate(RuntimeComponent component, RuntimeComponentReference reference) { + public void activate(CompositeContext compositeContext, RuntimeComponent component, RuntimeComponentReference reference) { if (logger.isLoggable(Level.FINE)) { logger.fine("Activating component reference: " + component.getURI() + "#" + reference.getName()); } @@ -641,7 +641,7 @@ public class CompositeActivatorImpl implements CompositeActivator { // Used by component context start // TODO - EPR I don't know why reference wires don't get added until component start - public void start(RuntimeComponent component, RuntimeComponentReference componentReference) { + public void start(CompositeContext compositeContext, RuntimeComponent component, RuntimeComponentReference componentReference) { synchronized (componentReference) { if (!(componentReference instanceof RuntimeComponentReference)) { @@ -696,7 +696,7 @@ public class CompositeActivatorImpl implements CompositeActivator { // current composite). Endpoint reference resolution takes place when the wire // is first used (when the chains are created) for (EndpointReference endpointReference : componentReference.getEndpointReferences()){ - addReferenceWire(component, componentReference, endpointReference); + addReferenceWire(compositeContext, component, componentReference, endpointReference); component.getComponentContext().getCompositeContext().getEndpointRegistry().addEndpointReference(endpointReference); } @@ -723,7 +723,7 @@ public class CompositeActivatorImpl implements CompositeActivator { } } - private void addReferenceWire(Component component, ComponentReference reference, EndpointReference endpointReference) { + private void addReferenceWire(CompositeContext compositeContext, Component component, ComponentReference reference, EndpointReference endpointReference) { RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference; // Use the interface contract of the reference on the component type and if there @@ -789,7 +789,7 @@ public class CompositeActivatorImpl implements CompositeActivator { // create the wire // null endpoint passed in here as the endpoint reference may // not be resolved yet - RuntimeWire wire = new RuntimeWireImpl(extensionPoints, + RuntimeWire wire = new RuntimeWireImpl(compositeContext, true, endpointReference, null, diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointRegistryImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointRegistryImpl.java index 1317c3fc8f..2ad61963e0 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointRegistryImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointRegistryImpl.java @@ -20,9 +20,8 @@ package org.apache.tuscany.sca.core.assembly.impl; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; import java.util.logging.Logger; import org.apache.tuscany.sca.assembly.Endpoint; @@ -38,25 +37,23 @@ import org.apache.tuscany.sca.runtime.EndpointRegistry; public class EndpointRegistryImpl implements EndpointRegistry, LifeCycleListener { private final Logger logger = Logger.getLogger(EndpointRegistryImpl.class.getName()); - private MappedList<EndpointRegistry, Endpoint> endpoints = new MappedList<EndpointRegistry, Endpoint>(); - private MappedList<EndpointRegistry, EndpointReference> endpointreferences = - new MappedList<EndpointRegistry, EndpointReference>(); + private List<Endpoint> endpoints = new ArrayList<Endpoint>(); + private List<EndpointReference> endpointreferences = new ArrayList<EndpointReference>(); + private List<EndpointListener> listeners = new ArrayList<EndpointListener>(); - private List<EndpointListener> listeners = new CopyOnWriteArrayList<EndpointListener>(); - - public EndpointRegistryImpl(ExtensionPointRegistry extensionPoints) { + public EndpointRegistryImpl(ExtensionPointRegistry extensionPoints, String endpointRegistryURI, String domainURI) { } - public void addEndpoint(Endpoint endpoint) { - endpoints.putValue(this, endpoint); + public synchronized void addEndpoint(Endpoint endpoint) { + endpoints.add(endpoint); for (EndpointListener listener : listeners) { listener.endpointAdded(endpoint); } logger.info("Add endpoint - " + endpoint.toString()); } - public void addEndpointReference(EndpointReference endpointReference) { - endpointreferences.putValue(this, endpointReference); + public synchronized void addEndpointReference(EndpointReference endpointReference) { + endpointreferences.add(endpointReference); logger.fine("Add endpoint reference - " + endpointReference.toString()); } @@ -104,153 +101,108 @@ public class EndpointRegistryImpl implements EndpointRegistry, LifeCycleListener return true; } - public List<Endpoint> findEndpoint(EndpointReference endpointReference) { + 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) { Endpoint targetEndpoint = endpointReference.getTargetEndpoint(); - for (List<Endpoint> collection : endpoints.values()) { - for (Endpoint endpoint : collection) { - // TODO: implement more complete matching - if (matches(targetEndpoint.getURI(), endpoint.getURI())) { - foundEndpoints.add(endpoint); - logger.fine("Found endpoint with matching service - " + endpoint); - } - // else the service name doesn't match + for (Endpoint endpoint : endpoints) { + // TODO: implement more complete matching + if (matches(targetEndpoint.getURI(), endpoint.getURI())) { + foundEndpoints.add(endpoint); + logger.fine("Found endpoint with matching service - " + endpoint); } + // else the service name doesn't match } } return foundEndpoints; } - public List<EndpointReference> findEndpointReference(Endpoint endpoint) { + public synchronized List<EndpointReference> findEndpointReference(Endpoint endpoint) { return null; } - public void removeEndpoint(Endpoint endpoint) { - endpoints.removeValue(this, endpoint); + 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 void removeEndpointReference(EndpointReference endpointReference) { - endpointreferences.removeValue(this, endpointReference); + public synchronized void removeEndpointReference(EndpointReference endpointReference) { + endpointreferences.remove(endpointReference); logger.fine("Remove endpoint reference - " + endpointReference.toString()); } - public List<EndpointReference> getEndpointRefereneces() { - return endpointreferences.getAllValues(); + public synchronized List<EndpointReference> getEndpointRefereneces() { + return endpointreferences; } - public List<Endpoint> getEndpoints() { - return endpoints.getAllValues(); + public synchronized List<Endpoint> getEndpoints() { + return endpoints; } - public void addListener(EndpointListener listener) { + public synchronized void addListener(EndpointListener listener) { listeners.add(listener); } - public List<EndpointListener> getListeners() { + public synchronized List<EndpointListener> getListeners() { return listeners; } - public void removeListener(EndpointListener listener) { + public synchronized void removeListener(EndpointListener listener) { listeners.remove(listener); } - public Endpoint getEndpoint(String uri) { - for (List<Endpoint> collection : endpoints.values()) { - for (Endpoint ep : collection) { - String epURI = - ep.getComponent().getURI() + "#" + ep.getService().getName() + "/" + ep.getBinding().getName(); + public synchronized Endpoint getEndpoint(String uri) { + for (Endpoint ep : endpoints) { + String epURI = + ep.getComponent().getURI() + "#" + ep.getService().getName() + "/" + ep.getBinding().getName(); + if (epURI.equals(uri)) { + return ep; + } + if (ep.getBinding().getName() == null || ep.getBinding().getName().equals(ep.getService().getName())) { + epURI = ep.getComponent().getURI() + "#" + ep.getService().getName(); if (epURI.equals(uri)) { return ep; } - if (ep.getBinding().getName() == null || ep.getBinding().getName().equals(ep.getService().getName())) { - epURI = ep.getComponent().getURI() + "#" + ep.getService().getName(); - if (epURI.equals(uri)) { - return ep; - } - } } } return null; } - public void updateEndpoint(String uri, Endpoint endpoint) { + public synchronized void updateEndpoint(String uri, Endpoint endpoint) { Endpoint oldEndpoint = getEndpoint(uri); if (oldEndpoint == null) { throw new IllegalArgumentException("Endpoint is not found: " + uri); } - endpoints.removeValue(this, oldEndpoint); - endpoints.putValue(this, endpoint); + endpoints.remove(oldEndpoint); + endpoints.add(endpoint); for (EndpointListener listener : listeners) { listener.endpointUpdated(oldEndpoint, endpoint); } } - public void start() { + public synchronized void start() { } - public void stop() { - List<Endpoint> localEndpoints = endpoints.remove(this); - if (localEndpoints != null) { - for (Endpoint endpoint : localEndpoints) { - removeEndpoint(endpoint); - } - } - List<EndpointReference> localEndpointReferences = endpointreferences.remove(this); - if (localEndpointReferences != null) { - for (EndpointReference endpointReference : localEndpointReferences) { - removeEndpointReference(endpointReference); - } + public synchronized void stop() { + for (Iterator<Endpoint> i = endpoints.iterator(); i.hasNext();) { + Endpoint ep = i.next(); + i.remove(); + endpointRemoved(ep); } + endpointreferences.clear(); listeners.clear(); } - private static class MappedList<K, V> extends ConcurrentHashMap<K, List<V>> { - private static final long serialVersionUID = -8926174610229029369L; - - public boolean putValue(K key, V value) { - List<V> collection = get(key); - if (collection == null) { - collection = new ArrayList<V>(); - put(key, collection); - } - return collection.add(value); - } - - public boolean putValue(K key, List<? extends V> value) { - List<V> collection = get(key); - if (collection == null) { - collection = new ArrayList<V>(); - put(key, collection); - } - return collection.addAll(value); - } - - public boolean removeValue(K key, V value) { - List<V> collection = get(key); - if (collection == null) { - return false; - } - return collection.remove(value); - } - - public List<V> getAllValues() { - List<V> values = new ArrayList<V>(); - for (List<V> collection : values()) { - values.addAll(collection); - } - return values; - } - - } - } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java index 4474c26deb..62b71c47d1 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java @@ -35,7 +35,7 @@ import org.apache.tuscany.sca.assembly.Contract; import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.EndpointReferenceBuilder; +import org.apache.tuscany.sca.context.CompositeContext; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; @@ -52,7 +52,6 @@ import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.invocation.Phase; -import org.apache.tuscany.sca.monitor.Problem; import org.apache.tuscany.sca.provider.BindingProviderFactory; import org.apache.tuscany.sca.provider.ImplementationProvider; import org.apache.tuscany.sca.provider.PolicyProvider; @@ -63,6 +62,7 @@ import org.apache.tuscany.sca.provider.ReferenceBindingProvider; import org.apache.tuscany.sca.provider.ReferenceBindingProviderRRB; import org.apache.tuscany.sca.provider.ServiceBindingProvider; import org.apache.tuscany.sca.provider.ServiceBindingProviderRRB; +import org.apache.tuscany.sca.runtime.EndpointReferenceBinder; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentReference; import org.apache.tuscany.sca.runtime.RuntimeComponentService; @@ -78,7 +78,8 @@ import org.oasisopen.sca.ServiceRuntimeException; */ public class RuntimeWireImpl implements RuntimeWire { - ExtensionPointRegistry extensionPoints; + private CompositeContext compositeContext; + private ExtensionPointRegistry extensionPoints; private Boolean isReferenceWire = false; private EndpointReference endpointReference; @@ -100,7 +101,7 @@ public class RuntimeWireImpl implements RuntimeWire { private List<InvocationChain> chains; private InvocationChain bindingInvocationChain; - private EndpointReferenceBuilder endpointReferenceBuilder; + private EndpointReferenceBinder eprBinder; private final ProviderFactoryExtensionPoint providerFactories; /** @@ -112,7 +113,7 @@ public class RuntimeWireImpl implements RuntimeWire { * @param messageFactory * @param conversationManager */ - public RuntimeWireImpl(ExtensionPointRegistry extensionPoints, + public RuntimeWireImpl(CompositeContext compositeContext, boolean isReferenceWire, EndpointReference endpointReference, Endpoint endpoint, @@ -121,7 +122,8 @@ public class RuntimeWireImpl implements RuntimeWire { RuntimeWireProcessor wireProcessor, MessageFactory messageFactory) { super(); - this.extensionPoints = extensionPoints; + this.compositeContext = compositeContext; + this.extensionPoints = compositeContext.getExtensionPointRegistry(); this.isReferenceWire = isReferenceWire; this.endpointReference = endpointReference; this.endpoint = endpoint; @@ -132,16 +134,17 @@ public class RuntimeWireImpl implements RuntimeWire { this.invoker = new RuntimeWireInvoker(this.messageFactory, this); UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - this.endpointReferenceBuilder = utilities.getUtility(EndpointReferenceBuilder.class); + this.eprBinder = utilities.getUtility(EndpointReferenceBinder.class); this.providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class); } - public RuntimeWireImpl(ExtensionPointRegistry extensionPoints, + public RuntimeWireImpl(CompositeContext compositeContext, boolean isReferenceWire, EndpointReference endpointReference, Endpoint endpoint) { super(); - this.extensionPoints = extensionPoints; + this.compositeContext = compositeContext; + this.extensionPoints = compositeContext.getExtensionPointRegistry(); this.isReferenceWire = isReferenceWire; this.endpointReference = endpointReference; this.endpoint = endpoint; @@ -154,9 +157,10 @@ public class RuntimeWireImpl implements RuntimeWire { this.messageFactory = factories.getFactory(MessageFactory.class); this.invoker = new RuntimeWireInvoker(this.messageFactory, this); - this.endpointReferenceBuilder = utilities.getUtility(EndpointReferenceBuilder.class); + this.eprBinder = utilities.getUtility(EndpointReferenceBinder.class); this.providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class); } + public synchronized List<InvocationChain> getInvocationChains() { if (chains == null) { initInvocationChains(); @@ -331,10 +335,10 @@ public class RuntimeWireImpl implements RuntimeWire { * is first used */ private void resolveEndpointReference(){ - Problem problem = endpointReferenceBuilder.runtimeBuild(endpointReference); + boolean ok = eprBinder.bind(compositeContext.getEndpointRegistry(), endpointReference); - if (problem != null){ - throw new SCARuntimeException(problem.toString()); + if (!ok) { + throw new SCARuntimeException("Unable to bind " + endpointReference); } // set the endpoint based on the resolved endpoint @@ -774,6 +778,6 @@ public class RuntimeWireImpl implements RuntimeWire { } public boolean isOutOfDate() { - return endpointReferenceBuilder.isOutOfDate(getEndpointReference()); + return eprBinder.isOutOfDate(compositeContext.getEndpointRegistry(), getEndpointReference()); } } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java index b88c395f31..d1bec6285c 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java @@ -34,7 +34,6 @@ import org.apache.tuscany.sca.assembly.Multiplicity; import org.apache.tuscany.sca.assembly.OptimizableBinding; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.EndpointReferenceBuilder; import org.apache.tuscany.sca.context.CompositeContext; import org.apache.tuscany.sca.context.ContextFactoryExtensionPoint; import org.apache.tuscany.sca.context.PropertyValueFactory; @@ -52,8 +51,8 @@ import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; -import org.apache.tuscany.sca.monitor.Problem; import org.apache.tuscany.sca.runtime.CompositeActivator; +import org.apache.tuscany.sca.runtime.EndpointReferenceBinder; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentContext; import org.apache.tuscany.sca.runtime.RuntimeComponentReference; @@ -78,7 +77,7 @@ public class ComponentContextImpl implements RuntimeComponentContext { private final AssemblyFactory assemblyFactory; private final JavaInterfaceFactory javaInterfaceFactory; private final PropertyValueFactory propertyFactory; - private final EndpointReferenceBuilder endpointReferenceBuilder; + private final EndpointReferenceBinder eprBinder; private final Monitor monitor; public ComponentContextImpl(ExtensionPointRegistry registry, CompositeContext compositeContext, RuntimeComponent component) { @@ -97,7 +96,7 @@ public class ComponentContextImpl implements RuntimeComponentContext { this.proxyFactory = new ExtensibleProxyFactory(registry.getExtensionPoint(ProxyFactoryExtensionPoint.class)); this.propertyFactory = factories.getFactory(PropertyValueFactory.class); - this.endpointReferenceBuilder = utilities.getUtility(EndpointReferenceBuilder.class); + this.eprBinder = utilities.getUtility(EndpointReferenceBinder.class); MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); this.monitor = monitorFactory.createMonitor(); @@ -394,10 +393,10 @@ public class ComponentContextImpl implements RuntimeComponentContext { componentReference.getEndpointReferences().add(endpointReference); // do binding matching - Problem problem = endpointReferenceBuilder.runtimeBuild(endpointReference); + boolean ok = eprBinder.bind(compositeContext.getEndpointRegistry(), endpointReference); - if (problem != null){ - throw new SCARuntimeException(problem.toString()); + if (!ok) { + throw new SCARuntimeException("Unable to bind " + endpointReference); } return componentReference; @@ -441,7 +440,7 @@ public class ComponentContextImpl implements RuntimeComponentContext { * @see org.apache.tuscany.sca.runtime.RuntimeComponentContext#start(org.apache.tuscany.sca.runtime.RuntimeComponentReference) */ public void start(RuntimeComponentReference reference) { - compositeActivator.start(component, reference); + compositeActivator.start(compositeContext, component, reference); } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/DefaultDomainRegistryFactory.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/DefaultDomainRegistryFactory.java new file mode 100644 index 0000000000..d80e2b5490 --- /dev/null +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/DefaultDomainRegistryFactory.java @@ -0,0 +1,157 @@ +/* + * 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.extensibility.ServiceDiscovery; +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 = ServiceDiscovery.getInstance().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 = "vm://localhost"; + } + + String key = endpointRegistryURI + "," + domainURI; + + EndpointRegistry endpointRegistry = endpointRegistries.get(key); + if (endpointRegistry != null) { + return endpointRegistry; + } + + URI uri = URI.create(endpointRegistryURI); + String scheme = uri.getScheme(); + if (scheme != null) { + scheme = scheme.toLowerCase(); + } + + 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); + } + 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/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointReferenceBuilderImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java index b37699580e..bab83bad2d 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointReferenceBuilderImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java @@ -17,15 +17,13 @@ * under the License. */ -package org.apache.tuscany.sca.core.assembly.impl; +package org.apache.tuscany.sca.core.runtime.impl; import java.util.List; import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference; -import org.apache.tuscany.sca.assembly.builder.EndpointReferenceBuilder; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; @@ -33,6 +31,7 @@ import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.runtime.EndpointReferenceBinder; import org.apache.tuscany.sca.runtime.EndpointRegistry; /** @@ -44,16 +43,15 @@ import org.apache.tuscany.sca.runtime.EndpointRegistry; * * @version $Rev$ $Date$ */ -public class EndpointReferenceBuilderImpl implements EndpointReferenceBuilder { +public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { protected ExtensionPointRegistry extensionPoints; protected AssemblyFactory assemblyFactory; protected InterfaceContractMapper interfaceContractMapper; - protected EndpointRegistry endpointRegistry; private Monitor monitor; - public EndpointReferenceBuilderImpl(ExtensionPointRegistry extensionPoints) { + public EndpointReferenceBinderImpl(ExtensionPointRegistry extensionPoints) { this.extensionPoints = extensionPoints; FactoryExtensionPoint factories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); @@ -61,24 +59,11 @@ public class EndpointReferenceBuilderImpl implements EndpointReferenceBuilder { UtilityExtensionPoint utils = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); this.interfaceContractMapper = utils.getUtility(InterfaceContractMapper.class); - this.endpointRegistry = utils.getUtility(EndpointRegistry.class); MonitorFactory monitorFactory = utils.getUtility(MonitorFactory.class); monitor = monitorFactory.createMonitor(); } - /** - * Build a composite - * - * @param endpoint - * @param monitor - */ - public void buildtimeBuild(Composite composite) { - // TODO - ready for reorganization of the builders - // build all the endpoint references in a composite - // that it is possible to build in order to get any - // errors out as early as possible. Any that can't - // be built now must wait until runtime - } + /** * Build a single endpoint reference @@ -86,10 +71,8 @@ public class EndpointReferenceBuilderImpl implements EndpointReferenceBuilder { * @param endpoint * @param monitor */ - public Problem runtimeBuild(EndpointReference endpointReference) { - + public boolean bind(EndpointRegistry endpointRegistry, EndpointReference endpointReference) { Problem problem = null; - if ( endpointReference.getStatus() == EndpointReference.WIRED_TARGET_FOUND_AND_MATCHED || endpointReference.getStatus() == EndpointReference.RESOLVED_BINDING ) { // The endpoint reference is already resolved to either @@ -142,7 +125,8 @@ public class EndpointReferenceBuilderImpl implements EndpointReferenceBuilder { } if (problem != null){ - return problem; + monitor.problem(problem); + return false; } if (endpointReference.getStatus() != EndpointReference.WIRED_TARGET_FOUND_AND_MATCHED && @@ -153,9 +137,12 @@ public class EndpointReferenceBuilderImpl implements EndpointReferenceBuilder { this, "EndpointReferenceCantBeMatched", endpointReference.toString()); + monitor.problem(problem); + return false; } - return problem; + return true; + } private Problem selectForwardEndpoint(EndpointReference endpointReference, List<Endpoint> endpoints) { @@ -170,6 +157,7 @@ public class EndpointReferenceBuilderImpl implements EndpointReferenceBuilder { for (Endpoint endpoint : endpoints){ if (haveMatchingPolicy(endpointReference, endpoint)){ matchedEndpoint = endpoint; + break; } } } @@ -299,7 +287,7 @@ public class EndpointReferenceBuilderImpl implements EndpointReferenceBuilder { return true; } - public boolean isOutOfDate(EndpointReference endpointReference) { + public boolean isOutOfDate(EndpointRegistry endpointRegistry, EndpointReference endpointReference) { Endpoint te = endpointReference.getTargetEndpoint(); if (!te.isUnresolved() && te.getURI()!= null) { List<Endpoint> endpoints = endpointRegistry.findEndpoint(endpointReference); diff --git a/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.AssemblyFactory b/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.AssemblyFactory new file mode 100644 index 0000000000..d30dc5b7d7 --- /dev/null +++ b/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.AssemblyFactory @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# Set the ranking to be greater than the DefaultAssemblyFactory
+org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory;ranking=100
\ No newline at end of file diff --git a/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.EndpointReferenceBuilder b/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory index 8f721db536..23c8ba044a 100644 --- a/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.EndpointReferenceBuilder +++ b/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory @@ -14,5 +14,4 @@ # 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.EndpointReferenceBuilderImpl
\ No newline at end of file +org.apache.tuscany.sca.core.runtime.DefaultDomainRegistryFactory
diff --git a/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointReferenceBinder b/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointReferenceBinder new file mode 100644 index 0000000000..9315a855b2 --- /dev/null +++ b/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointReferenceBinder @@ -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.core.runtime.impl.EndpointReferenceBinderImpl
|