From 2e0a5f4c1368993c8cf71b9f4b59273a323b9aff Mon Sep 17 00:00:00 2001 From: antelder Date: Thu, 28 Jul 2011 11:07:25 +0000 Subject: Recreate 2.0-Beta3 branch from current trunk git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1151792 13f79535-47bb-0310-9956-ffa450edef68 --- .../tuscany/sca/runtime/ActivationException.java | 37 ++++ .../apache/tuscany/sca/runtime/ActiveNodes.java | 32 ++++ .../tuscany/sca/runtime/BaseDomainRegistry.java | 198 +++++++++++++++++++++ .../sca/runtime/BaseDomainRegistryFactory.java | 115 ++++++++++++ .../tuscany/sca/runtime/CompositeActivator.java | 159 +++++++++++++++++ .../sca/runtime/ContributionDescription.java | 157 ++++++++++++++++ .../tuscany/sca/runtime/ContributionListener.java | 29 +++ ...DefaultDomainRegistryFactoryExtensionPoint.java | 103 +++++++++++ .../DefaultWireProcessorExtensionPoint.java | 127 +++++++++++++ .../apache/tuscany/sca/runtime/DomainRegistry.java | 108 +++++++++++ .../tuscany/sca/runtime/DomainRegistryFactory.java | 61 +++++++ .../DomainRegistryFactoryExtensionPoint.java | 51 ++++++ .../tuscany/sca/runtime/DomainRegistryURI.java | 168 +++++++++++++++++ .../tuscany/sca/runtime/EndpointListener.java | 46 +++++ .../sca/runtime/EndpointReferenceBinder.java | 53 ++++++ .../tuscany/sca/runtime/EndpointSerializer.java | 36 ++++ .../runtime/ExtensibleDomainRegistryFactory.java | 156 ++++++++++++++++ .../org/apache/tuscany/sca/runtime/Invocable.java | 162 +++++++++++++++++ .../tuscany/sca/runtime/ReferenceParameters.java | 59 ++++++ .../tuscany/sca/runtime/RuntimeComponent.java | 96 ++++++++++ .../sca/runtime/RuntimeComponentContext.java | 65 +++++++ .../sca/runtime/RuntimeComponentReference.java | 44 +++++ .../sca/runtime/RuntimeComponentService.java | 33 ++++ .../tuscany/sca/runtime/RuntimeEndpoint.java | 102 +++++++++++ .../sca/runtime/RuntimeEndpointReference.java | 96 ++++++++++ .../tuscany/sca/runtime/RuntimeProperties.java | 37 ++++ .../tuscany/sca/runtime/RuntimeWireProcessor.java | 39 ++++ .../RuntimeWireProcessorExtensionPoint.java | 53 ++++++ .../sca/runtime/UnknownEndpointHandler.java | 29 +++ .../org/apache/tuscany/sca/runtime/Version.java | 47 +++++ 30 files changed, 2498 insertions(+) create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActivationException.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActiveNodes.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseDomainRegistry.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseDomainRegistryFactory.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/CompositeActivator.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ContributionDescription.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ContributionListener.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultDomainRegistryFactoryExtensionPoint.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistry.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactory.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactoryExtensionPoint.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryURI.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointListener.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReferenceBinder.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointSerializer.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ExtensibleDomainRegistryFactory.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/Invocable.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ReferenceParameters.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpoint.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpointReference.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeProperties.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/UnknownEndpointHandler.java create mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/Version.java (limited to 'sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime') diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActivationException.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActivationException.java new file mode 100644 index 0000000000..b015891e93 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActivationException.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.runtime; + + +/** + * Denotes an error starting the runtime + * + * @version $Rev$ $Date$ + */ +public class ActivationException extends Exception { + private static final long serialVersionUID = 8612661660934426123L; + + public ActivationException(String message) { + super(message); + } + + public ActivationException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActiveNodes.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActiveNodes.java new file mode 100644 index 0000000000..c3b6527181 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActiveNodes.java @@ -0,0 +1,32 @@ +/* + * 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.List; + +public class ActiveNodes { + + List activeNodes = new ArrayList(); + + public List getActiveNodes() { + return activeNodes; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseDomainRegistry.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseDomainRegistry.java new file mode 100644 index 0000000000..3d9d2cb14c --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseDomainRegistry.java @@ -0,0 +1,198 @@ +/* + * 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 javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Base; +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.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.LifeCycleListener; + +/** + * A replicated DomainRegistry based on Apache Tomcat Tribes + * @tuscany.spi.extension.inheritfrom + */ +public abstract class BaseDomainRegistry implements DomainRegistry, LifeCycleListener { + protected final static Logger logger = Logger.getLogger(BaseDomainRegistry.class.getName()); + + protected String domainRegistryURI; + protected String domainURI; + + protected List endpointreferences = new CopyOnWriteArrayList(); + protected List listeners = new CopyOnWriteArrayList(); + protected List contributionlisteners = new CopyOnWriteArrayList(); + protected ExtensionPointRegistry registry; + protected Map attributes; + + public BaseDomainRegistry(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); + ((RuntimeEndpointReference)endpointReference).bind(registry, this); + logger.fine("Add endpoint reference - " + endpointReference); + } + + public void addEndpointListener(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 boolean isOutOfDate(EndpointReference endpointReference) { + return ! findEndpoint(endpointReference).contains(endpointReference.getTargetEndpoint()); + } + + public List findEndpoint(EndpointReference endpointReference) { + logger.fine("Find endpoint for reference - " + endpointReference); + + if (endpointReference.getReference() != null) { + Endpoint targetEndpoint = endpointReference.getTargetEndpoint(); + String uri = targetEndpoint.getURI(); + // [rfeng] This is a workaround to deal with the case that the endpoint URI doesn't have the + // service name to avoid confusion between structural URIs and service URIs + if (uri.indexOf('#') == -1) { + uri = uri + "#service()"; + } + return findEndpoint(uri); + } + + return new ArrayList(); + } + + public abstract List findEndpoint(String uri); + + public List findEndpointReference(Endpoint endpoint) { + return endpointreferences; + } + + /** + * Returns a list of EndpointReferences that have a URI that matches a given URI + * @param uri - the URI to match + * @return a List of EndpointReferences that match the supplied URI - if there are none + * an *empty* list is returned (not null) + */ + public List findEndpointReferences( String uri ) { + List theRefs = new ArrayList(); + if( uri == null ) return theRefs; + + for( EndpointReference ref : endpointreferences ) { + if( uri.equals(ref.getURI()) ) theRefs.add(ref); + } // end for + + return theRefs; + } // end method findEndpointReference + + public abstract Endpoint getEndpoint(String uri); + + public List getEndpointReferences() { + return endpointreferences; + } + + public abstract Collection getEndpoints(); + + public List getListeners() { + return listeners; + } + + public abstract void removeEndpoint(Endpoint endpoint); + + public void removeEndpointReference(EndpointReference endpointReference) { + endpointreferences.remove(endpointReference); + logger.fine("Remove endpoint reference - " + endpointReference); + } + + public void removeEndpointListener(EndpointListener listener) { + listeners.remove(listener); + } + + public String getDomainURI() { + return domainRegistryURI; + } + + public String getDomainName() { + return domainURI; + } + + public void addContributionListener(ContributionListener listener) { + contributionlisteners.add(listener); + } + + public void removeContributionListener(ContributionListener listener) { + contributionlisteners.remove(listener); + } + + public Composite getDomainComposite() { + FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class); + Composite domainComposite = assemblyFactory.createComposite(); + domainComposite.setName(new QName(Base.SCA11_TUSCANY_NS, getDomainName())); + domainComposite.setAutowire(false); + domainComposite.setLocal(false); + List domainIncludes = domainComposite.getIncludes(); + Map> runningCompositeURIs = getRunningCompositeURIs(); + for (String curi : runningCompositeURIs.keySet()) { + for (String compositeURI : runningCompositeURIs.get(curi)) { + domainIncludes.add(getRunningComposite(curi, compositeURI)); + } + } + return domainComposite; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseDomainRegistryFactory.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseDomainRegistryFactory.java new file mode 100644 index 0000000000..ce38eb4eee --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseDomainRegistryFactory.java @@ -0,0 +1,115 @@ +/* + * 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 + * @tuscany.spi.extension.inheritfrom + */ +public abstract class BaseDomainRegistryFactory implements DomainRegistryFactory, LifeCycleListener { + protected ExtensionPointRegistry registry; + protected Map domainRegistries = new ConcurrentHashMap(); + protected List listeners = new ArrayList(); + + /** + * @param extensionRegistry + */ + public BaseDomainRegistryFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + public void start() { + } + + public synchronized DomainRegistry getEndpointRegistry(String endpointRegistryURI, String domainURI) { + if (endpointRegistryURI == null) { + endpointRegistryURI = domainURI; + } + + Object key = getKey(endpointRegistryURI, domainURI); + + DomainRegistry domainRegistry = domainRegistries.get(key); + if (domainRegistry != null) { + return domainRegistry; + } + + domainRegistry = createEndpointRegistry(endpointRegistryURI, domainURI); + + if (domainRegistry instanceof LifeCycleListener) { + ((LifeCycleListener)domainRegistry).start(); + } + + for (EndpointListener listener : listeners) { + domainRegistry.addEndpointListener(listener); + } + domainRegistries.put(key, domainRegistry); + return domainRegistry; + } + + protected Object getKey(String endpointRegistryURI, String domainURI) { + return endpointRegistryURI + "," + domainURI; + } + + protected abstract DomainRegistry createEndpointRegistry(String endpointRegistryURI, String domainURI); + + public void stop() { + for (DomainRegistry domainRegistry : domainRegistries.values()) { + if (domainRegistry instanceof LifeCycleListener) { + ((LifeCycleListener)domainRegistry).stop(); + } + } + domainRegistries.clear(); + listeners.clear(); + } + + public synchronized Collection getEndpointRegistries() { + return new ArrayList(domainRegistries.values()); + } + + public synchronized void addListener(EndpointListener listener) { + listeners.add(listener); + for (DomainRegistry registry : domainRegistries.values()) { + registry.addEndpointListener(listener); + } + } + + public synchronized List getListeners() { + return listeners; + } + + public synchronized void removeListener(EndpointListener listener) { + listeners.remove(listener); + for (DomainRegistry registry : domainRegistries.values()) { + registry.removeEndpointListener(listener); + } + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/CompositeActivator.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/CompositeActivator.java new file mode 100644 index 0000000000..d9bdc2b6f6 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/CompositeActivator.java @@ -0,0 +1,159 @@ +/* + * 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 org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.context.CompositeContext; + +/** + * Start/stop a composite + * + * @version $Rev$ $Date$ + */ +public interface CompositeActivator { + /** + * Activate a composite + * @param compositeContext The context of the Node + * @param composite + */ + void activate(CompositeContext compositeContext, Composite composite) throws ActivationException; + + /** + * Activate a component reference + * @param compositeContext The context of the Node + * @param component + * @param ref + */ + void activate(CompositeContext compositeContext, RuntimeComponent component, RuntimeComponentReference ref); + + /** + * Activate a component reference + * @param compositeContext The context of the Node + * @param component + * @param ref + */ + void activate(CompositeContext compositeContext, RuntimeComponent component, RuntimeComponentService service); + + /** + * De-activate a component reference + * @param component + * @param ref + */ + void deactivate(RuntimeComponent component, RuntimeComponentReference ref); + + /** + * De-activate a component reference + * @param component + * @param ref + */ + void deactivate(RuntimeComponent component, RuntimeComponentService service); + + /** + * Stop a composite + * @param composite + */ + void deactivate(Composite composite) throws ActivationException; + + /** + * Start a component reference + * @param compositeContext The context of the Node + * @param component + * @param ref + */ + void start(CompositeContext compositeContext, RuntimeComponent component, RuntimeComponentReference ref); + + + /** + * Start a component + * @param component + */ + void start(CompositeContext compositeContext, Component component) throws ActivationException; + + /** + * Stop a component + * @param component + */ + void stop(CompositeContext compositeContext, Component component) throws ActivationException; + + /** + * Start components in a composite + * @param composite + */ + void start(CompositeContext compositeContext, Composite composite) throws ActivationException; + + /** + * Stop components in a composite + * @param composite + */ + void stop(CompositeContext compositeContext, Composite composite) throws ActivationException; + + /** + * Activate an endpoint + * @param compositeContext + * @param endpoint + */ + void activate(CompositeContext compositeContext, RuntimeEndpoint endpoint); + + /** + * Activate an endpoint reference + * @param compositeContext + * @param endpointReference + */ + void activate(CompositeContext compositeContext, RuntimeEndpointReference endpointReference); + + /** + * Deactivate an endpoint + * @param endpoint + */ + void deactivate(RuntimeEndpoint endpoint); + + /** + * Deactivate an endpoint reference + * @param endpointReference + */ + void deactivate(RuntimeEndpointReference endpointReference); + + /** + * Start an endpoint + * @param compositeContext + * @param endpoint + */ + void start(CompositeContext compositeContext, RuntimeEndpoint endpoint); + + /** + * Start an endpoint reference + * @param compositeContext + * @param endpointReference + */ + void start(CompositeContext compositeContext, RuntimeEndpointReference endpointReference); + + /** + * Stop an endpoint + * @param endpoint + */ + void stop(RuntimeEndpoint endpoint); + + /** + * Stop an endpoint reference + * @param endpointReference + */ + void stop(RuntimeEndpointReference endpointReference); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ContributionDescription.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ContributionDescription.java new file mode 100644 index 0000000000..6ddffb06da --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ContributionDescription.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.runtime; + +import java.io.File; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.java.JavaExport; +import org.apache.tuscany.sca.contribution.java.JavaImport; +import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; +import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; + +public class ContributionDescription implements Serializable { + private static final long serialVersionUID = 1L; + + private String uri; + private String url; + private List dependentContributionURIs = new ArrayList(); + + // the URIs of the deployable composites within the contribution + private List deployables = new ArrayList(); + + // TODO: Handle Imports and Exports in a more extensible way + private List javaExports = new ArrayList(); + private List namespaceExports = new ArrayList(); + private List javaImports = new ArrayList(); + private List namespaceImports = new ArrayList(); + + // the URI and XML content of composites to include in the contribution + private Map additionalDeployables = new HashMap(); + + public ContributionDescription(String url) { + this(null, url); + } + public ContributionDescription(String uri, String url) { + this.url = url; + this.uri = uri; + if (uri == null || uri.length() < 1) { + this.uri = deriveContributionURI(url); + } + } + + public String getURI() { + return uri; + } + public String getURL() { + return url; + } + public List getDeployables() { + return deployables; + } + public void setDeployables(List deployables) { + this.deployables = deployables; + } + public List getDependentContributionURIs() { + return dependentContributionURIs; + } + public Map getAdditionalDeployables() { + return additionalDeployables; + } + public List getJavaExports() { + return javaExports; + } + public List getNamespaceExports() { + return namespaceExports; + } + public List getJavaImports() { + return javaImports; + } + public List getNamespaceImports() { + return namespaceImports; + } + + public void configureMetaData(Contribution contribution) { + + if (contribution.getDeployables() != null) { + for (Composite composite : contribution.getDeployables()) { + getDeployables().add(composite.getURI()); + } + } + + if (contribution.getExports() != null) { + for (Export export : contribution.getExports()) { + // TODO: Handle these and others in a more extensible way + if (export instanceof JavaExport) { + getJavaExports().add(((JavaExport)export).getPackage()); + } else if (export instanceof NamespaceExport) { + getNamespaceExports().add(((NamespaceExport)export).getNamespace()); + } + } + } + + if (contribution.getImports() != null) { + for (Import imprt : contribution.getImports()) { + // TODO: Handle these and others in a more extensible way + if (imprt instanceof JavaImport) { + getJavaImports().add(((JavaImport)imprt).getPackage()); + } else if (imprt instanceof NamespaceImport) { + getNamespaceImports().add(((NamespaceImport)imprt).getNamespace()); + } + } + } + } + + /** + * Derives a URI for the contribution based on its URL + */ + protected String deriveContributionURI(String contributionURL) { + String uri = null; + try { + File f = new File(contributionURL); + if ("classes".equals(f.getName()) && "target".equals(f.getParentFile().getName())) { + uri = f.getParentFile().getParentFile().getName(); + } else { + uri = f.getName(); + } + } catch (Exception e) { + // ignore + } + if (uri == null) { + uri = contributionURL; + } + if (uri.endsWith(".zip") || uri.endsWith(".jar")) { + uri = uri.substring(0, uri.length() - 4); + } + if (uri.endsWith("SNAPSHOT")) { + uri = uri.substring(0, uri.lastIndexOf('-')); + uri = uri.substring(0, uri.lastIndexOf('-')); + } + return uri; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ContributionListener.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ContributionListener.java new file mode 100644 index 0000000000..d1eba27a79 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ContributionListener.java @@ -0,0 +1,29 @@ +/* + * 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.EventListener; + +public interface ContributionListener extends EventListener { + + void contributionRemoved(String uri); + + void contributionUpdated(String uri); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultDomainRegistryFactoryExtensionPoint.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultDomainRegistryFactoryExtensionPoint.java new file mode 100644 index 0000000000..f74d80b882 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultDomainRegistryFactoryExtensionPoint.java @@ -0,0 +1,103 @@ +/* + * 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.HashMap; +import java.util.List; +import java.util.Map; + +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; + +/** + * Default implementation of DomainRegistryFactoryExtensionPoint + */ +public class DefaultDomainRegistryFactoryExtensionPoint implements DomainRegistryFactoryExtensionPoint, + LifeCycleListener { + private ExtensionPointRegistry registry; + private boolean loaded; + private List factories = new ArrayList(); + private Map domainRegistryMapping = new HashMap(); + + /** + * @param registry + */ + public DefaultDomainRegistryFactoryExtensionPoint(ExtensionPointRegistry registry, Map attributes) { + super(); + this.registry = registry; + // Populate the domainRegistryMapping + domainRegistryMapping.putAll(attributes); + domainRegistryMapping.remove("class"); + domainRegistryMapping.remove("ranking"); + } + + 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() { + // Empty + } + + public void stop() { + ServiceHelper.stop(factories); + } + + public Map getDomainRegistryMapping() { + return domainRegistryMapping; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java new file mode 100644 index 0000000000..283d1d1a8b --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java @@ -0,0 +1,127 @@ +/* + * 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.lang.reflect.Constructor; +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.ServiceDiscovery; + +/** + * The default implementation of a WireProcessorExtensionPoint + * + * @version $Rev$ $Date$ + */ +public class DefaultWireProcessorExtensionPoint implements RuntimeWireProcessorExtensionPoint, LifeCycleListener { + private ExtensionPointRegistry registry; + private boolean loaded; + + /** + * @param registry + */ + public DefaultWireProcessorExtensionPoint(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + /** + * The list of WireProcessors available to the runtime + */ + private final List processors = new ArrayList(); + + /** + * Registers a wire-processor in the runtime + * + * @param processor The processor to register + */ + public void addWireProcessor(RuntimeWireProcessor processor) { + processors.add(processor); + if (processor instanceof LifeCycleListener) { + ((LifeCycleListener)processor).start(); + } + } + + /** + * De-registers a wire-processor in the runtime + * + * @param processor The processor to de-register + */ + public void removeWireProcessor(RuntimeWireProcessor processor) { + boolean found = processors.remove(processor); + if (found && (processor instanceof LifeCycleListener)) { + ((LifeCycleListener)processor).stop(); + } + } + + /** + * Returns a list of registered wire-processors. + * + * @return The list of wire processors + */ + public List getWireProcessors() { + loadWireProcessors(); + return processors; + } + + private synchronized void loadWireProcessors() { + if (loaded) { + return; + } + try { + Collection sds = + registry.getServiceDiscovery().getServiceDeclarations(RuntimeWireProcessor.class, true); + for (ServiceDeclaration sd : sds) { + Class type = sd.loadClass(); + Constructor constructor = null; + RuntimeWireProcessor processor = null; + try { + constructor = type.getConstructor(ExtensionPointRegistry.class); + processor = (RuntimeWireProcessor)constructor.newInstance(registry); + + } catch (NoSuchMethodException e) { + constructor = type.getConstructor(); + processor = (RuntimeWireProcessor)constructor.newInstance(); + } + if (processor != null) { + addWireProcessor(processor); + } + } + loaded = true; + } catch (Throwable e) { + throw new IllegalStateException(e); + } + } + + public void start() { + } + + public void stop() { + for (RuntimeWireProcessor processor : processors) { + if ((processor instanceof LifeCycleListener)) { + ((LifeCycleListener)processor).stop(); + } + } + processors.clear(); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistry.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistry.java new file mode 100644 index 0000000000..c33d3c1a4b --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistry.java @@ -0,0 +1,108 @@ +/* + * 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.Collection; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; + +/** + * The DomainRegistry holds the active service endpoints for the SCA domain + * @tuscany.spi.extension.inheritfrom + */ +public interface DomainRegistry { + /** + * 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); + + /** + * Get all endpoints in the registry + * @return + */ + Collection getEndpoints(); + + List findEndpoint(String uri); + List findEndpoint(EndpointReference endpointReference); + + void addEndpointReference(EndpointReference endpointReference); + void removeEndpointReference(EndpointReference endpointReference); + // List findEndpointReference(Endpoint endpoint); + List getEndpointReferences(); + + boolean isOutOfDate(EndpointReference endpointReference); + + /** + * Returns a list of EndpointReferences that have a URI that matches a given URI + * @param uri - the URI to match + * @return a List of EndpointReferences that match the supplied URI - if there are none + * an *empty* list is returned (not null) + */ + public List findEndpointReferences( String uri ); + + void addEndpointListener(EndpointListener listener); + void removeEndpointListener(EndpointListener listener); + + String getDomainURI(); + String getDomainName(); + + void installContribution(ContributionDescription cd); + void uninstallContribution(String uri); + List getInstalledContributionURIs(); + ContributionDescription getInstalledContribution(String uri); + void updateInstalledContribution(ContributionDescription cd); + + void addContributionListener(ContributionListener listener); + void removeContributionListener(ContributionListener listener); + + void addRunningComposite(String contributionURI, Composite composite); + void removeRunningComposite(String contributionURI, String compositeURI); + Map> getRunningCompositeURIs(); + Composite getRunningComposite(String contributionURI, String compositeURI); + + String getContainingCompositesContributionURI(String componentName); + + List getNodeNames(); + String getLocalNodeName(); + String getRunningNodeName(String contributionURI, String compositeURI); + + String remoteCommand(String memberName, Callable command); + public Composite getDomainComposite(); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactory.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactory.java new file mode 100644 index 0000000000..69ed07763e --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactory.java @@ -0,0 +1,61 @@ +/* + * 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.Collection; + +/** + * A DomainRegistryFactory is responsible for creating an instance of the DomainRegistry for a given + * registry URI and domain URI + */ +public interface DomainRegistryFactory { + /** + * Get the DomainRegistry for the given registry URI and domain URI + * @param endpointRegistryURI A URI can be used to connect to the registry, such as vm://localhost + * or multicast://200.0.100.200:50000/... + * @param domainURI The domain URI + * @return + */ + DomainRegistry getEndpointRegistry(String endpointRegistryURI, String domainURI); + + /** + * Return all active endpoint registries + * @return + */ + Collection getEndpointRegistries(); + + /** + * Add an EndpointListener + * @param listener + */ + void addListener(EndpointListener listener); + + /** + * Remove an EndpointListener + * @param listener + */ + void removeListener(EndpointListener listener); + + /** + * Return an array of schemes that this factory supports + * @return + */ + String[] getSupportedSchemes(); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactoryExtensionPoint.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactoryExtensionPoint.java new file mode 100644 index 0000000000..f1582c3d70 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactoryExtensionPoint.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.runtime; + +import java.util.List; +import java.util.Map; + +/** + * Extension point for DomainRegistryFactory + */ +public interface DomainRegistryFactoryExtensionPoint { + /** + * Return a mapping between domain URI and domain registry URI + * @return A mutable map + */ + Map getDomainRegistryMapping(); + + /** + * Add a DomainRegistryFactory + * @param factory + */ + void addDomainRegistryFactory(DomainRegistryFactory factory); + + /** + * Remove a DomainRegistryFactory + * @param factory + */ + void removeDomainRegistryFactory(DomainRegistryFactory factory); + + /** + * @return A list of DomainRegistryFactory + */ + List getDomainRegistryFactories(); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryURI.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryURI.java new file mode 100644 index 0000000000..6de0878383 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryURI.java @@ -0,0 +1,168 @@ +/* + * 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.HashMap; +import java.util.List; +import java.util.Map; + + +/** + * Utility to parse the config uri string. + * + * tuscany:[domainName]?listen=[port|ip:port]]&password=abc&multicast=[off|port|ip:port]&remotes=ip:port,ip:port,... + + * listen - defines the local bind address and port, it defaults to all network interfaces on port 14820 and if that port in use it will try incrementing by one till a free port is found. + * password - is the password other nodes must use to connect to this domain. The default is 'tuscany'. + * multicast - defines if multicast discovery is used and if so what multicast ip group and port is used. + * The default is multicast is off if remotes= is specified (only for now due to a Hazelcast limitation that is planned to be fixed), + * otherwise if remotes= is not specified then multicast defaults to 224.5.12.10:51482 + * remotes - a list of ipAddress:port for remote nodes + * + * @tuscany.spi.extension.asclient + * + */ +public class DomainRegistryURI { + + private String domainName = "default"; + private String bindAddress = null; // null means all network adapters + private int listenPort = 14820; + private String password = "tuscany"; + private boolean multicastDisabled = false; + private String multicastAddress = "224.5.12.10"; + private int multicastPort = 51482; + private List remotes = new ArrayList(); + private String uri; + + public DomainRegistryURI(String uri) { + this.uri = uri; + parseURI(uri); + } + + private void parseURI(String uri) { + if (uri.startsWith("tuscanyclient:")) { + uri = uri.replace("tuscanyclient:", "tuscany:"); + } + + if (!uri.startsWith("tuscany:")) { + throw new IllegalArgumentException("Config URI must start with 'tuscany:'"); + } + + // make it a URI so java.net.URI can be used to parse it + int i = uri.indexOf(":"); + if (uri.charAt("tuscany:".length()) != '/') { + uri = uri.replaceFirst(":", ":/"); + } + if (uri.charAt("tuscany:".length()+1) != '/') { + uri = uri.replaceFirst(":/", "://"); + } + URI configURI = URI.create(uri); + + this.domainName = configURI.getHost(); + + String query = configURI.getQuery(); + if (query != null && query.length() > 0) { + String[] params = query.split("&"); + Map paramMap = new HashMap(); + for (String param : params) { + paramMap.put(param.split("=")[0], param.split("=")[1]); + } + for (String name : paramMap.keySet()) { + String value = paramMap.get(name); + if ("listen".equals(name)) { + if (value.indexOf(":") == -1) { + this.listenPort = Integer.parseInt(value); + } else { + String[] addr = value.split(":"); + this.bindAddress = addr[0]; + this.listenPort = Integer.parseInt(addr[1]); + } + } else if ("multicast".equals(name)) { + if ("off".equalsIgnoreCase(value)) { + this.multicastDisabled = true; + } else { + if (value.indexOf(":") == -1) { + this.multicastAddress = value; + } else { + String[] addr = value.split(":"); + this.multicastAddress = addr[0]; + this.multicastPort = Integer.parseInt(addr[1]); + } + } + } else if ("password".equals(name)) { + this.password = value; + } else if ("remotes".equals(name)) { + String[] ips = value.split(","); + for (String ip : ips) { + if (ip.indexOf(":") == -1) { + remotes.add(ip + ":14820"); + } else { + remotes.add(ip); + } + } + if (paramMap.containsKey("multicast")) { +// throw new IllegalArgumentException("Cannot have multicast and remotes (for now)"); + } else { + this.multicastDisabled = true; + } + } + } + } + } + + public String getDomainName() { + return domainName; + } + + public String getBindAddress() { + return bindAddress; + } + + public int getListenPort() { + return listenPort; + } + + public String getPassword() { + return password; + } + + public boolean isMulticastDisabled() { + return multicastDisabled; + } + + public String getMulticastAddress() { + return multicastAddress; + } + + public int getMulticastPort() { + return multicastPort; + } + + public List getRemotes() { + return remotes; + } + + public String toString() { + return uri; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointListener.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointListener.java new file mode 100644 index 0000000000..13d193c464 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointListener.java @@ -0,0 +1,46 @@ +/* + * 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.EventListener; + +import org.apache.tuscany.sca.assembly.Endpoint; + +/** + * A listener for endpoint events + */ +public interface EndpointListener extends EventListener { + /** + * The method is invoked when a new endpoint is added to the registry + * @param endpoint + */ + void endpointAdded(Endpoint endpoint); + /** + * The method is invoked when an endpoint is removed the registry + * @param endpoint + */ + void endpointRemoved(Endpoint endpoint); + /** + * The method is invoked when an endpoint is updated in the registry + * @param oldEndpoint + * @param newEndpoint + */ + void endpointUpdated(Endpoint oldEndpoint, Endpoint newEndpoint); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReferenceBinder.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReferenceBinder.java new file mode 100644 index 0000000000..79e8dfc475 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReferenceBinder.java @@ -0,0 +1,53 @@ +/* + * 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 org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; + +/** + * A utility responsible for resolving the endpoint reference against a matching endpoint published + * to the DomainRegistry + */ +public interface EndpointReferenceBinder { + + /** + * @param domainRegistry + * @param endpointReference + * @return + */ + void bindBuildTime(DomainRegistry domainRegistry, EndpointReference endpointReference, BuilderContext builderContext); + + + /** + * @param domainRegistry + * @param endpointReference + * @return + */ + void bindRunTime(DomainRegistry domainRegistry, EndpointReference endpointReference); + + /** + * + * @param domainRegistry + * @param endpointReference + * @return + */ + boolean isOutOfDate(DomainRegistry domainRegistry, EndpointReference endpointReference); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointSerializer.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointSerializer.java new file mode 100644 index 0000000000..981872fdfa --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointSerializer.java @@ -0,0 +1,36 @@ +/* + * 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 org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; + +/** + * A utility to seralize/deserialize Endpoint/EndpointReference objects + */ +public interface EndpointSerializer { + EndpointReference readEndpointReference(String xml); + + String write(EndpointReference endpointReference); + + Endpoint readEndpoint(String xml); + + String write(Endpoint endpoint); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ExtensibleDomainRegistryFactory.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ExtensibleDomainRegistryFactory.java new file mode 100644 index 0000000000..ddb4279a4e --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ExtensibleDomainRegistryFactory.java @@ -0,0 +1,156 @@ +/* + * 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.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.oasisopen.sca.ServiceRuntimeException; + +/** + * A delegating DomainRegistryFactory + */ +public class ExtensibleDomainRegistryFactory implements DomainRegistryFactory { + private final DomainRegistryFactoryExtensionPoint factories; + private String[] allSchemes; + private String defaultScheme = "vm"; + + public ExtensibleDomainRegistryFactory(ExtensionPointRegistry registry) { + this.factories = registry.getExtensionPoint(DomainRegistryFactoryExtensionPoint.class); + RuntimeProperties ps = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(RuntimeProperties.class); + if (ps.getProperties().containsKey("defaultScheme")) { + defaultScheme = ps.getProperties().getProperty("defaultScheme"); + } + + } + + public ExtensibleDomainRegistryFactory(DomainRegistryFactoryExtensionPoint factories) { + this.factories = factories; + } + + public static ExtensibleDomainRegistryFactory getInstance(ExtensionPointRegistry registry) { + UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); + return utilities.getUtility(ExtensibleDomainRegistryFactory.class); + } + + 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 DomainRegistry getEndpointRegistry(String endpointRegistryURI, String domainURI) { + if (domainURI == null) { + domainURI = getDomainName(endpointRegistryURI); + } + if (endpointRegistryURI == null) { + endpointRegistryURI = factories.getDomainRegistryMapping().get(domainURI); + if (endpointRegistryURI == null) { + endpointRegistryURI = domainURI; + } + } + + String scheme = endpointRegistryURI == null ? null : URI.create(endpointRegistryURI).getScheme(); + if (scheme == null) { + + // See if there is a previously created registry for that domain + for (DomainRegistryFactory factory : factories.getDomainRegistryFactories()) { + for (DomainRegistry domainRegistry : factory.getEndpointRegistries()) { + if (domainRegistry.getDomainURI().equals(domainURI)) { + return domainRegistry; + } + } + } + + scheme = defaultScheme; + endpointRegistryURI = scheme + ":" + endpointRegistryURI; + } else { + scheme = scheme.toLowerCase(); + } + for (DomainRegistryFactory factory : factories.getDomainRegistryFactories()) { + String[] schemes = factory.getSupportedSchemes(); + if (schemes != null && Arrays.asList(schemes).contains(scheme)) { + DomainRegistry domainRegistry = factory.getEndpointRegistry(endpointRegistryURI, domainURI); + if (domainRegistry == null) { + continue; + } else { + return domainRegistry; + } + } + } + throw new ServiceRuntimeException("No DomainRegistry can support " + endpointRegistryURI); + } + + public void removeListener(EndpointListener listener) { + for (DomainRegistryFactory factory : factories.getDomainRegistryFactories()) { + factory.removeListener(listener); + } + } + + public synchronized String[] getSupportedSchemes() { + if (allSchemes == null) { + Set supportedSchemes = new HashSet(); + for (DomainRegistryFactory factory : factories.getDomainRegistryFactories()) { + String[] schemes = factory.getSupportedSchemes(); + if (schemes != null) { + supportedSchemes.addAll(Arrays.asList(schemes)); + } + } + allSchemes = supportedSchemes.toArray(new String[supportedSchemes.size()]); + } + return allSchemes; + } + + /** + * Derive a domain name from a domain URI + * Examples: + * Domain URI - Domain Name + * default default + * foo foo + * uri:foo foo + * uri://foo?key=x&key2=y foo + * uri://foo/bar foo/bar + */ + private static String getDomainName(String domainURI) { + int scheme = domainURI.indexOf(':'); + int qm = domainURI.indexOf('?'); + if (qm == -1) { + return domainURI.substring(scheme+1); + } else { + return domainURI.substring(scheme+1, qm); + } + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/Invocable.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/Invocable.java new file mode 100644 index 0000000000..78a87191de --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/Invocable.java @@ -0,0 +1,162 @@ +/* + * 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.lang.reflect.InvocationTargetException; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.context.CompositeContext; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.provider.PolicyProvider; + +/** + * The abstraction of an invocable model that contains invocation chains + * @tuscany.spi.extension.asclient + */ +public interface Invocable { + /** + * Bind the invocable to the composite context + * @param context + */ + void bind(CompositeContext context); + + /** + * Bind the invocable to the extension point registry and endpoint registry. This is typically + * called after the endpoint or endpoint reference is deserialized + * @param registry + * @param domainRegistry + */ + void bind(ExtensionPointRegistry registry, DomainRegistry domainRegistry); + + /** + * Get the associated composite context + * @return + */ + CompositeContext getCompositeContext(); + + /** + * Unbind the invocable from the composite context + */ + void unbind(); + + /** + * Get the component + * @return + */ + Component getComponent(); + + /** + * Get the service or reference (contract) + * @return + */ + Contract getContract(); + + /** + * Get the binding + * @return + */ + Binding getBinding(); + + /** + * Returns the invocation chains for service operations associated with the + * wire + * + * @return the invocation chains for service operations associated with the + * wire + */ + List getInvocationChains(); + + /** + * Lookup the invocation chain by operation + * @param operation The operation + * @return The invocation chain for the given operation + */ + InvocationChain getInvocationChain(Operation operation); + + /** + * Get the invocation chain for the binding-specific handling + * @return The binding invocation chain + */ + InvocationChain getBindingInvocationChain(); + + /** + * This invoke method assumes that the binding invocation chain is in force + * and that there will be an operation selector element there to + * determine which operation to call + * @param msg The request message + * @return The response message + */ + Message invoke(Message msg); + + /** + * Invoke an operation with given arguments + * @param operation The operation + * @param args The arguments + * @return The result + * @throws InvocationTargetException + */ + Object invoke(Operation operation, Object[] args) throws InvocationTargetException; + + /** + * Invoke an operation with a context message + * @param operation The operation + * @param msg The request message + * @return The response message + * @throws InvocationTargetException + */ + Message invoke(Operation operation, Message msg); + + /** + * Asynchronously invoke an operation with a context message + * @param operation The operation + * @param msg The request message + * @return The ticket that can be used to identify this invocation + * @throws InvocationTargetException + */ + void invokeAsync(Operation operation, Message msg); + + /** + * Asynchronously invoke an operation with a context message + * This invoke method assumes that the binding invocation chain is in force + * and that there will be an operation selector element there to + * determine which operation to call + * @param msg The request message + */ + void invokeAsync(Message msg); + + /** + * Asynchronously invoke an operation with a context message + * @param tailInvoker the invoker at the end of the chain + * @param msg The request message + */ + void invokeAsyncResponse(Message msg); + + /** + * Get a list of policy providers + * @return + */ + List getPolicyProviders(); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ReferenceParameters.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ReferenceParameters.java new file mode 100644 index 0000000000..928c77fd04 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ReferenceParameters.java @@ -0,0 +1,59 @@ +/* + * 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 org.apache.tuscany.sca.assembly.EndpointReference; + +/** + * Parameters for the EndPointReference + * + * @version $Rev$ $Date$ + */ +public interface ReferenceParameters extends Cloneable { + /** + * Get the callback ID + * @return the callbackID + */ + Object getCallbackID(); + + /** + * Set the callback ID + * @param callbackID the callbackID to set + */ + void setCallbackID(Object callbackID); + + /** + * Get the ID for the non-ServiceReference callback object + * @return + */ + Object getCallbackObjectID(); + + /** + * Set the ID for the non-ServiceReference callback object + * @param callbackObjectID + */ + void setCallbackObjectID(Object callbackObjectID); + + EndpointReference getCallbackReference(); + + void setCallbackReference(EndpointReference callback); + + Object clone() throws CloneNotSupportedException; +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.java new file mode 100644 index 0000000000..01b0111e59 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.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.util.List; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.oasisopen.sca.ServiceReference; + +/** + * The runtime component interface. Provides the bridge between the + * assembly model representation of a component and its runtime + * realization. + * + * @version $Rev$ $Date$ + * @tuscany.spi.extension.asclient + */ +public interface RuntimeComponent extends Component { + /** + * Set the implementation-specific configuration for this component + * @param implementationProvider The object that manages the component implementation + */ + void setImplementationProvider(ImplementationProvider implementationProvider); + + /** + * Get the implementation-specific configuration for this component + * @return The implementation provider for this component + */ + ImplementationProvider getImplementationProvider(); + + /** + * Get the associated component context + * @return + */ + RuntimeComponentContext getComponentContext(); + + /** + * Set the associated component context + * @param context + */ + void setComponentContext(RuntimeComponentContext context); + + /** + * Tests if the RuntimeComponent is started + * @return true if the RuntimeComponent is started otherwise false + */ + boolean isStarted(); + + /** + * Sets the RuntimeComponent started state + * @param started the state to set + */ + void setStarted(boolean started); + + /** + * Add a policy provider to the component + * @param policyProvider + */ + void addPolicyProvider(PolicyProvider policyProvider); + + /** + * Get a list of policy providers configured for this component + * @return + */ + List getPolicyProviders(); + + + /** + * Returns a ServiceReference for a service provided by the component + * + * @param businessInterface the interface that will be used to invoke the service + * @param serviceName the name of the service + * @param the Java type of the business interface for the service + * @return an object that implements the business interface + */ + ServiceReference getServiceReference(Class businessInterface, String name); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java new file mode 100644 index 0000000000..cf2042a0ae --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java @@ -0,0 +1,65 @@ +/* + * 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 org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.context.CompositeContext; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.oasisopen.sca.ComponentContext; +import org.oasisopen.sca.ServiceReference; + +/** + * @version $Rev$ $Date$ + */ +public interface RuntimeComponentContext extends ComponentContext { + + /** + * Get the CallableReference for a given component reference + * @param + * @param businessInterface The business interface + * @param endpointReference The endpointReference to be used + * @return A service reference representing the wire + */ + ServiceReference getServiceReference(Class businessInterface, + RuntimeEndpointReference endpointReference); + + + /** + * Create a CallableReference for the given component service + * @param + * @param businessInterface + * @param component + * @param service + * @return + */ + ServiceReference getServiceReference(Class businessInterface, RuntimeEndpoint endpoint); + + /** + * @param + * @param businessInterface + * @param service + * @return + */ + ServiceReference createSelfReference(Class businessInterface, ComponentService service); + + ExtensionPointRegistry getExtensionPointRegistry(); + + CompositeContext getCompositeContext(); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java new file mode 100644 index 0000000000..5dc114ade0 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java @@ -0,0 +1,44 @@ +/* + * 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 org.apache.tuscany.sca.assembly.ComponentReference; + +/** + * The runtime component reference. Provides the bridge between the + * assembly model representation of a component reference and its runtime + * realization + * + * @version $Rev$ $Date$ + * @tuscany.spi.extension.asclient + */ +public interface RuntimeComponentReference extends ComponentReference { + /** + * Set the owning component + * @param component + */ + void setComponent(RuntimeComponent component); + + /** + * Get the owning component + * @return the owning component + */ + RuntimeComponent getComponent(); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java new file mode 100644 index 0000000000..1eefdc978e --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.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 org.apache.tuscany.sca.assembly.ComponentService; + +/** + * The runtime component service. Provides the bridge between the + * assembly model representation of a component service and its runtime + * realization + * + * @version $Rev$ $Date$ + * @tuscany.spi.extension.asclient + */ +public interface RuntimeComponentService extends ComponentService { +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpoint.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpoint.java new file mode 100644 index 0000000000..b45def3e95 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpoint.java @@ -0,0 +1,102 @@ +/* + * 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.io.Serializable; + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.context.CompositeContext; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; + +/** + * The runtime representation of a service endpoint + * @tuscany.spi.extension.asclient + */ +public interface RuntimeEndpoint extends Endpoint, Invocable, Serializable { + /** + * Attach the service binding provider + * @param provider + */ + void setBindingProvider(ServiceBindingProvider provider); + + /** + * Get the service binding provider + * @return + */ + ServiceBindingProvider getBindingProvider(); + + /** + * Get the interface contract for the binding. This represents the data types that the binding + * protocol stack can process. + * @return The binding interface contract + */ + InterfaceContract getBindingInterfaceContract(); + + /** + * Get the interface contract of the service of the target component type, i.e., the + * componentType.service.interfaceContract. This represents the data types that the implementation + * code can process. + * @return The target component type service interface contract + */ + InterfaceContract getComponentTypeServiceInterfaceContract(); + + + /** + * Check that endpoint has compatible interface at the component and binding ends. + * The user can specify the interfaces at both ends so there is a danger that they won't be compatible. + */ + void validateServiceInterfaceCompatibility(); + + /** + * Get the composite context for the composite that contains this endpoint. This + * is useful for accessing various composite level objects from within the + * runtime code + */ + CompositeContext getCompositeContext(); + + /** + * Retrieve the normalized WSDL contract relating to the input WSDL contract + * + * @param interfaceContract + * @return + */ + public InterfaceContract getGeneratedWSDLContract(InterfaceContract interfaceContract); + + /** + * Creates the async callback for this Endpoint, if it does not already exist + * and stores it into the Endpoint + */ + public void createAsyncServerCallback( ); + + /** + * Gets the async callback reference for this Endpoint, if it exists + * @return + */ + public RuntimeEndpointReference getAsyncServerCallback(); + + /** + * Get/Set the endpoint that this endpoint delegates to. This only + * comes into play when this endpoint is configured with an SCA bindng + */ + RuntimeEndpoint getDelegateEndpoint(); + void setDelegateEndpoint(RuntimeEndpoint delegateEndpoint); + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpointReference.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpointReference.java new file mode 100644 index 0000000000..dbdd458543 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeEndpointReference.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.io.Serializable; + +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; + +/** + * The runtime representation of an endpoint reference + * @tuscany.spi.extension.asclient + */ +public interface RuntimeEndpointReference extends EndpointReference, Invocable, Serializable { + /** + * Set the reference binding provider for the endpoint reference + * @param provider The binding provider + */ + void setBindingProvider(ReferenceBindingProvider provider); + + /** + * Get the reference binding provider for the endpoint reference + * @return The binding provider + */ + ReferenceBindingProvider getBindingProvider(); + + /** + * Get the interface contract for the binding. This represents the data types that the binding + * protocol stack can process. + * @return The binding interface contract + */ + InterfaceContract getBindingInterfaceContract(); + + + /** + * Get the interface contract of the reference of the source component type, i.e., the + * componentType.reference.interfaceContract. This represents the data types that the + * implementation code uses to make the outbound call. + * @return The source component type reference interface contract + */ + InterfaceContract getComponentTypeReferenceInterfaceContract(); + + /** + * Check that endpoint reference has compatible interface at the component and binding ends. + * The user can specify the interfaces at both ends so there is a danger that they won't be compatible. + * There is checking in the activator but of course endpoint references may not have a binding assigned + * until final resolution. + */ + public void validateReferenceInterfaceCompatibility(); + + boolean isOutOfDate(); + void rebuild(); + boolean isStarted(); + + /** + * Retrieve the normalized WSDL contract relating to the input WSDL contract + * + * @param interfaceContract + * @return + */ + public InterfaceContract getGeneratedWSDLContract(InterfaceContract interfaceContract); + + /** + * Create the endpoint which will be the target of and asynchronous response to a + * message sent through this reference. We have the code here as this can't be done + * in the builders in the same was as callbacks are because we don't know the details + * of the endpoint until the endpoint reference has been resolved. + */ + public void createAsyncCallbackEndpoint(); + + /** + * Get/Set the endpoint reference that this endpoint reference delegates to. This only + * comes into play when this endpoint reference is configured with an SCA bindng + */ + RuntimeEndpointReference getDelegateEndpointReference(); + void setDelegateEndpointReference(RuntimeEndpointReference delegateEndpointReference); + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeProperties.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeProperties.java new file mode 100644 index 0000000000..0e02d2cd94 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeProperties.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.runtime; + +import java.util.Properties; +/** + * + * @tuscany.spi.extension.asclient + * + */ +public interface RuntimeProperties { + + /** + * When true log with Level.FINE instead of Level.INFO + */ + public static final String QUIET_LOGGING = "org.apache.tuscany.sca.quietLogging"; + + Properties getProperties(); + void setProperties(Properties properties); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java new file mode 100644 index 0000000000..997e170b22 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java @@ -0,0 +1,39 @@ +/* + * 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; + +/** + * Implementations are called after wires are decorated with policy and before they are connected. + * + * @version $Rev$ $Date$ + * @tuscany.spi.extension.inheritfrom + */ +public interface RuntimeWireProcessor { + /** + * Configure the runtime endpoint + * @param endpoint + */ + void process(RuntimeEndpoint endpoint); + + /** + * Configure the runtime endpoint reference + * @param endpointReference + */ + void process(RuntimeEndpointReference endpointReference); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java new file mode 100644 index 0000000000..4b2c71b397 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java @@ -0,0 +1,53 @@ +/* + * 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; + +/** + * Acts as a delegating WireProcessorExtensionPoint, delegating + * processing of wires after policies have been applied and source and targets + * have been connected. + * + * @version $Rev$ $Date$ + */ +public interface RuntimeWireProcessorExtensionPoint { + + /** + * Registers a wire-processor in the runtime + * + * @param processor The processor to register + */ + void addWireProcessor(RuntimeWireProcessor processor); + + /** + * De-registers a wire-processor in the runtime + * + * @param processor The processor to de-register + */ + void removeWireProcessor(RuntimeWireProcessor processor); + + /** + * Returns a list of registered wire-processors. + * + * @return The list of wire processors + */ + List getWireProcessors(); + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/UnknownEndpointHandler.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/UnknownEndpointHandler.java new file mode 100644 index 0000000000..cfb205f489 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/UnknownEndpointHandler.java @@ -0,0 +1,29 @@ +/* + * 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 org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.EndpointReference; + +public interface UnknownEndpointHandler { + + Binding handleUnknownEndpoint(EndpointReference endpointReference); + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/Version.java b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/Version.java new file mode 100644 index 0000000000..5d3ed1ce41 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/Version.java @@ -0,0 +1,47 @@ +/* + * 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.ResourceBundle; + +public class Version { + + public static final String VERSION; + public static final String REVISION; + public static final String BUILDTIME; + static { + ResourceBundle rb = ResourceBundle.getBundle("org/apache/tuscany/sca/runtime/revision"); + VERSION = rb.getString("version"); + REVISION = rb.getString("revision"); + BUILDTIME = rb.getString("buildtime"); + } + + public static String getVersion() { + return VERSION; + } + + public static String getRevsion() { + return REVISION; + } + + public static String getBuildTime() { + return BUILDTIME; + } +} -- cgit v1.2.3