diff options
Diffstat (limited to '')
9 files changed, 161 insertions, 75 deletions
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiDistributionProvider.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiDistributionProvider.java new file mode 100644 index 0000000000..ff30730c78 --- /dev/null +++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiDistributionProvider.java @@ -0,0 +1,99 @@ +/* + * 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.implementation.osgi.runtime; + +import java.util.Collection; +import java.util.Map; + +import org.osgi.framework.ServiceReference; + +/** + * Every Distribution Provider registers exactly one Service in the + * ServiceRegistry implementing this interface. The service is registered with + * extra properties identified at the beginning of this interface to denote the + * Distribution Provider product name, version, vendor and supported intents. + */ +public interface OSGiDistributionProvider { + + /** + * Service Registration property for the name of the Distribution Provider + * product. + */ + static final String PROP_KEY_PRODUCT_NAME = "osgi.remote.distribution.product"; + + /** + * Service Registration property for the version of the Distribution + * Provider product. + */ + static final String PROP_KEY_PRODUCT_VERSION = "osgi.remote.distribution.product.version"; + + /** + * Service Registration property for the Distribution Provider product + * vendor name. + */ + static final String PROP_KEY_VENDOR_NAME = "osgi.remote.distribution.vendor"; + + /** + * Service Registration property that lists the intents supported by this + * DistributionProvider. Value of this property is of type + * Collection (<? extends String>). + */ + static final String PROP_KEY_SUPPORTED_INTENTS = "osgi.remote.distribition.supported_intents"; + + /** + * @return ServiceReferences of services registered in the local Service + * Registry that are proxies to remote services. If no proxies are + * registered, then an empty collection is returned. + */ + Collection<ServiceReference> getRemoteServices(); + + /** + * @return ServiceReferences of local services that are exposed remotely + * using this DisitributionProvider. Note that certain services may be + * exposed and without being published to a discovery service. This + * API returns all the exposed services. If no services are exposed an + * empty collection is returned. + */ + Collection<ServiceReference> getExposedServices(); + + /** + * Provides access to extra properties set by the DistributionProvider on + * endpoints, as they will appear on client side proxies given an exposed + * ServiceReference. + * These properties are not always available on the server-side + * ServiceReference of the exposed + * service but will be on the remote client side proxy to this service. + * This API provides access to these extra properties from the exposing + * side. + * E.g. a service is exposed remotely, the distribution software is configured + * to add transactionality to the remote service. Because of this, on the + * client-side proxy the property service.intents=”transactionality” is set. + * However, these intents are *not* always set on the original + * ServiceRegistration on the server-side since on the server side the service + * object is a local pojo which doesn’t provide transactionality by itself. + * This QoS is added by the distribution. + * This API provides access to these extra properties from the server-side. + * + * @param sr A ServiceReference of an exposed service. + * @return The map of extra properties. + */ + Map<String, String> getExposedProperties(ServiceReference sr); + +} diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java index 5e592ee97a..ddcd49a235 100644 --- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java +++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java @@ -72,9 +72,12 @@ public class OSGiImplementationProvider implements ImplementationProvider { JavaInterface javaInterface = (JavaInterface)interfaceContract.getInterface(); final Class<?> interfaceClass = javaInterface.getJavaClass(); - final Hashtable<String, Object> targetProperties = getOSGiProperties(reference); - targetProperties.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE); - targetProperties.put("sca.reference", component.getURI() + "#reference(" + ref.getName() + ")"); + final Hashtable<String, Object> osgiProps = getOSGiProperties(reference); + osgiProps.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE); + osgiProps.put("sca.reference", component.getURI() + "#reference(" + ref.getName() + ")"); + osgiProps.put(OSGiProperty.OSGI_REMOTE, "true"); + osgiProps.put(OSGiProperty.OSGI_REMOTE_CONFIGURATION_TYPE, "sca"); + osgiProps.put(OSGiProperty.OSGI_REMOTE_INTERFACES, interfaceClass.getName()); ProxyFactory proxyService = proxyFactoryExtensionPoint.getInterfaceProxyFactory(); if (!interfaceClass.isInterface()) { @@ -87,7 +90,7 @@ public class OSGiImplementationProvider implements ImplementationProvider { public ServiceRegistration run() { return osgiBundle.getBundleContext().registerService(interfaceClass.getName(), proxy, - targetProperties); + osgiProps); } }); } diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java index 8509e866ef..26b588a099 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java @@ -28,6 +28,21 @@ public interface OSGiProperty { String NAME = "name"; QName PROPERTY_QNAME = new QName(OSGiImplementation.SCA11_TUSCANY_NS, "osgi.property"); + /** + * Standard OSGi property names + */ + String OSGI_REMOTE = "osgi.remote"; + String SERVICE_INTENTS = "service.intents"; + String OSGI_REMOTE_INTERFACES = "osgi.remote.interfaces"; + String OSGI_REMOTE_INTENTS = "osgi.remote.requires.intents"; + String OSGI_REMOTE_CONFIGURATION_TYPE = "osgi.remote.configuration.type"; + String SCA_BINDINGS = "osgi.remote.configuration.sca.bindings"; + String SCA_REFERENCE = "osgi.remote.configuration.sca.reference"; + String SCA_SERVICE = "osgi.remote.configuration.sca.service"; + String SCA_REFERENCE_BINDING = "osgi.remote.configuration.sca.reference.binding"; + String SCA_SERVICE_BINDING = "osgi.remote.configuration.sca.service.binding"; + String OSGI_REMOTE_CONFIGURATION_TYPE_SCA = "sca"; + String getValue(); void setValue(String value); diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescription.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescription.java index 832e26a48f..119d7ed657 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescription.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescription.java @@ -22,12 +22,19 @@ package org.apache.tuscany.sca.implementation.osgi; import java.util.List; import java.util.Map; - /** * The OSGi RFC 119 description of a remote OSGi service */ public interface ServiceDescription { + /** + * Get a list of interfaces + * @return + */ List<String> getInterfaces(); + /** + * Get a list of properties + * @return + */ Map<String, Object> getProperties(); } diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptions.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptions.java index 36968615c0..35866938d6 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptions.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/ServiceDescriptions.java @@ -23,7 +23,6 @@ import java.util.List; import javax.xml.namespace.QName; - /** * OSGi RFC 119 service descriptions */ @@ -34,9 +33,4 @@ public interface ServiceDescriptions extends List<ServiceDescription> { QName SERVICE_DESCRIPTIONS_QNAME = new QName(OSGI_SD_NS, "service-descriptions"); QName SERVICE_DESCRIPTION_QNAME = new QName(OSGI_SD_NS, "service-description"); String REMOTE_SERVICE_HEADER = "Remote-Service"; - String PROP_SERVICE_INTENTS = "service.intents"; - String PROP_REQUIRES_INTENTS = "osgi.remote.requires.intents"; - String PROP_CONFIGURATION_TYPE = "osgi.remote.configuration.type"; - String CONFIGURATION_TYPE_SCA = "sca"; - String PROP_CONFIGURATION_SCA_BINDINGS = "osgi.remote.configuration.sca.bindings"; } diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java index d9641def69..41deef131f 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationImpl.java @@ -18,14 +18,11 @@ */ package org.apache.tuscany.sca.implementation.osgi.impl; -import java.util.Hashtable; -import java.util.List; - -import org.apache.tuscany.sca.assembly.ComponentProperty; import org.apache.tuscany.sca.assembly.impl.ImplementationImpl; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation; import org.osgi.framework.Bundle; +import org.osgi.framework.Constants; /** * OSGi implementation @@ -40,41 +37,20 @@ public class OSGiImplementationImpl extends ImplementationImpl implements OSGiIm private String bundleVersion; private Bundle osgiBundle; - private Hashtable<String, List<ComponentProperty>> referenceProperties; - private Hashtable<String, List<ComponentProperty>> serviceProperties; - - private Hashtable<String, List<ComponentProperty>> referenceCallbackProperties; - private Hashtable<String, List<ComponentProperty>> serviceCallbackProperties; - private FactoryExtensionPoint modelFactories; - protected OSGiImplementationImpl(FactoryExtensionPoint modelFactories) { this.modelFactories = modelFactories; } - public OSGiImplementationImpl(FactoryExtensionPoint modelFactories, - String bundleSymbolicName, - String bundleVersion, - Hashtable<String, List<ComponentProperty>> refProperties, - Hashtable<String, List<ComponentProperty>> serviceProperties) { + public OSGiImplementationImpl(FactoryExtensionPoint modelFactories, String bundleSymbolicName, String bundleVersion) { super(); this.bundleSymbolicName = bundleSymbolicName; this.bundleVersion = bundleVersion; - this.referenceProperties = refProperties; - this.serviceProperties = serviceProperties; this.modelFactories = modelFactories; } - public void setCallbackProperties(Hashtable<String, List<ComponentProperty>> refCallbackProperties, - Hashtable<String, List<ComponentProperty>> serviceCallbackProperties) { - - this.referenceCallbackProperties = refCallbackProperties; - this.serviceCallbackProperties = serviceCallbackProperties; - - } - public String getBundleSymbolicName() { return bundleSymbolicName; } @@ -87,22 +63,6 @@ public class OSGiImplementationImpl extends ImplementationImpl implements OSGiIm return modelFactories; } - public List<ComponentProperty> getReferenceProperties(String referenceName) { - return referenceProperties.get(referenceName); - } - - public List<ComponentProperty> getServiceProperties(String serviceName) { - return serviceProperties.get(serviceName); - } - - public List<ComponentProperty> getReferenceCallbackProperties(String referenceName) { - return referenceCallbackProperties.get(referenceName); - } - - public List<ComponentProperty> getServiceCallbackProperties(String serviceName) { - return serviceCallbackProperties.get(serviceName); - } - /** * Since OSGi implementation annotations may not be processed until much later, leave it to * the OSGi invoker to decide whether pass-by-reference is allowed. @@ -118,6 +78,10 @@ public class OSGiImplementationImpl extends ImplementationImpl implements OSGiIm public void setBundle(Bundle osgiBundle) { this.osgiBundle = osgiBundle; + if (osgiBundle != null) { + this.bundleSymbolicName = osgiBundle.getSymbolicName(); + this.bundleVersion = (String)osgiBundle.getHeaders().get(Constants.BUNDLE_VERSION); + } } private boolean areEqual(Object obj1, Object obj2) { @@ -138,14 +102,6 @@ public class OSGiImplementationImpl extends ImplementationImpl implements OSGiIm return false; if (!areEqual(bundleVersion, impl.bundleVersion)) return false; - if (!areEqual(serviceProperties, impl.serviceProperties)) - return false; - if (!areEqual(serviceCallbackProperties, impl.serviceCallbackProperties)) - return false; - if (!areEqual(referenceProperties, impl.referenceProperties)) - return false; - if (!areEqual(referenceCallbackProperties, impl.referenceCallbackProperties)) - return false; return super.equals(obj); } diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionImpl.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionImpl.java index eeacdb9702..b990cf5980 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionImpl.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/ServiceDescriptionImpl.java @@ -30,13 +30,13 @@ import org.apache.tuscany.sca.implementation.osgi.ServiceDescription; * The OSGi RFC 119 description of a remote OSGi service */ public class ServiceDescriptionImpl implements ServiceDescription { + private List<String> interfaces = new ArrayList<String>(); + private Map<String, Object> properties = new HashMap<String, Object>(); + protected ServiceDescriptionImpl() { super(); } - private List<String> interfaces = new ArrayList<String>(); - private Map<String, Object> properties = new HashMap<String, Object>(); - public List<String> getInterfaces() { return interfaces; } @@ -46,6 +46,6 @@ public class ServiceDescriptionImpl implements ServiceDescription { } public String toString() { - return "service-description: interfaces=" + interfaces + "properties=" + properties; + return "service-description: interfaces=" + interfaces + " properties=" + properties; } -}
\ No newline at end of file +} diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java index 0a0efd1ec1..57d360ca29 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java @@ -45,6 +45,7 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation; import org.apache.tuscany.sca.implementation.osgi.OSGiImplementationFactory; +import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory; import org.apache.tuscany.sca.interfacedef.Interface; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.monitor.Monitor; @@ -65,13 +66,13 @@ import org.osgi.framework.Version; */ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiImplementation> { private AssemblyFactory assemblyFactory; - // private FactoryExtensionPoint modelFactories; + private ServiceDescriptionsFactory serviceDescriptionsFactory; private OSGiImplementationFactory osgiImplementationFactory; private Monitor monitor; public OSGiImplementationProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { this.monitor = monitor; - // this.modelFactories = modelFactories; + this.serviceDescriptionsFactory = modelFactories.getFactory(ServiceDescriptionsFactory.class); this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); this.osgiImplementationFactory = modelFactories.getFactory(OSGiImplementationFactory.class); } @@ -171,8 +172,15 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm error("MissingComponentTypeFile", impl, componentType.getURI()); //throw new ContributionResolveException("missing .componentType side file " + ctURI); return; + } else { + mergeFromComponentType(impl, componentType, resolver); } + // FIXME: How to find the RFC 119 service descriptions in the contribution and + // derive the SCA component type from them? + } + + private void mergeFromComponentType(OSGiImplementation impl, ComponentType componentType, ModelResolver resolver) { List<Service> services = componentType.getServices(); for (Service service : services) { Interface interfaze = service.getInterfaceContract().getInterface(); @@ -211,7 +219,6 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm impl.getProperties().add(property); } impl.setConstrainingType(componentType.getConstrainingType()); - } private Class<?> getJavaClass(ModelResolver resolver, String className) { diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java index 7a4ae3e6de..436143ad6c 100644 --- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java +++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java @@ -38,13 +38,18 @@ import org.junit.Test; */ public class ServiceDescriptionsTestCase { private static final String xml = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<service-descriptions xmlns=\"http://www.osgi.org/xmlns/sd/v1.0.0\">" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + + "<service-descriptions xmlns=\"http://www.osgi.org/xmlns/sd/v1.0.0\" " + +"xmlns:sca=\"http://docs.oasis-open.org/ns/opencsa/sca/200903\">" + "<service-description>" - + "<provide interface=\"com.iona.soa.pojo.hello.HelloService\"/>" - + "<property name=\"service.intents\">SOAP HTTP</property>" - + "<property name=\"osgi.remote.configuration.type\">pojo</property>" - + "<property name=\"osgi.remote.configuration.pojo.address\">" - + "http://localhost:9000/hello" + + "<provide interface=\"calculator.operations.AddService\"/>" + + "<property name=\"service.intents\">sca:SOAP sca:HTTP</property>" + + "<property name=\"osgi.remote.configuration.type\">sca</property>" + + "<property name=\"osgi.remote.configuration.sca.componentType\">" + + "OSGI-INF/sca/bundle.componentType" + + "</property>" + + "<property name=\"osgi.remote.configuration.sca.reference\">" + + "addService" + "</property>" + "</service-description>" + "<service-description>" |