You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2009/06/30 20:08:12 UTC

svn commit: r789859 - in /tuscany/java/sca/modules/implementation-osgi-runtime: META-INF/ src/main/java/org/apache/tuscany/sca/dosgi/discovery/ src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/ src/main/java/org/osgi/service/distribution/

Author: rfeng
Date: Tue Jun 30 18:08:11 2009
New Revision: 789859

URL: http://svn.apache.org/viewvc?rev=789859&view=rev
Log:
Starting to hook distribution/discovery services

Added:
    tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/distribution/
    tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/distribution/DistributionProvider.java
Modified:
    tuscany/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF
    tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java
    tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveryActivator.java
    tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java
    tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiDistributionProvider.java
    tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java
    tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java

Modified: tuscany/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF?rev=789859&r1=789858&r2=789859&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF (original)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF Tue Jun 30 18:08:11 2009
@@ -29,4 +29,5 @@
  org.osgi.util.tracker
 Bundle-DocURL: http://www.apache.org/
 Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
-Export-Package: org.osgi.service.discovery;version="1.0"
+Export-Package: org.osgi.service.discovery;version="1.0",
+ org.osgi.service.distribution;version="1.0"

Modified: tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java?rev=789859&r1=789858&r2=789859&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java (original)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java Tue Jun 30 18:08:11 2009
@@ -318,6 +318,14 @@
         }
     }
 
+    /**
+     * Publish the OSGi services that are exposed to SCA. For SCA, the replicated endpoint registry
+     * serves are the discovery protocol. The OSGi services are added to endpoint registry first before
+     * the ServicePublication services are registered so that othe Discovery services can see them.
+     * @param ref
+     * @param endpoint
+     * @return
+     */
     protected ServiceRegistration localServicePublished(ServiceReference ref, Endpoint endpoint) {
         EndpointPublication publication = new EndpointPublication(ref, endpoint);
         ServiceRegistration registration =

Modified: tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveryActivator.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveryActivator.java?rev=789859&r1=789858&r2=789859&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveryActivator.java (original)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveryActivator.java Tue Jun 30 18:08:11 2009
@@ -37,8 +37,12 @@
         discoveryServices.add(new DomainDiscoveryService(context));
 
         for (AbstractDiscoveryService service : discoveryServices) {
+            Hashtable<String, Object> props = new Hashtable<String, Object>();
+            props.put(Discovery.PRODUCT_NAME, "Apache Tuscany SCA");
+            props.put(Discovery.PRODUCT_VERSION, "2.0.0");
+            props.put(Discovery.VENDOR_NAME, "Apache Software Foundation");
             ServiceRegistration registration =
-                context.registerService(Discovery.class.getName(), service, new Hashtable<String, Object>());
+                context.registerService(Discovery.class.getName(), service, props);
             discoveryServiceRegistrations.add(registration);
         }
     }

Modified: tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java?rev=789859&r1=789858&r2=789859&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java (original)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java Tue Jun 30 18:08:11 2009
@@ -90,7 +90,7 @@
             servicesInfo.put(sed, b);
             serviceDescriptionAdded(sed);
         }
-        throw new RuntimeException("To be implemented");
+        // throw new RuntimeException("To be implemented");
     }
 
     private void removeServicesDeclaredInBundle(Bundle bundle) {

Modified: tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiDistributionProvider.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiDistributionProvider.java?rev=789859&r1=789858&r2=789859&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiDistributionProvider.java (original)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiDistributionProvider.java Tue Jun 30 18:08:11 2009
@@ -6,94 +6,60 @@
  * 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.    
+ * under the License.
  */
 
 package org.apache.tuscany.sca.implementation.osgi.runtime;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.Map;
 
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
+import org.osgi.service.distribution.DistributionProvider;
 
 /**
- * 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.
+ * OSGi distribution provider
  */
-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);
-
+public class OSGiDistributionProvider implements DistributionProvider {
+    private BundleContext bundleContext;
+    private Collection<ServiceReference> exposedServices = new ArrayList<ServiceReference>();
+    private Collection<ServiceReference> remoteServices = new ArrayList<ServiceReference>();
+
+    public OSGiDistributionProvider(BundleContext bundleContext) {
+        super();
+        this.bundleContext = bundleContext;
+    }
+
+    public Map<String, String> getExposedProperties(ServiceReference sr) {
+        return Collections.emptyMap();
+    }
+
+    public Collection<ServiceReference> getExposedServices() {
+        return exposedServices;
+    }
+
+    public Collection<ServiceReference> getRemoteServices() {
+        return remoteServices;
+    }
+
+    public Dictionary<String, Object> getProperties() {
+        Hashtable<String, Object> props = new Hashtable<String, Object>();
+        props.put(PRODUCT_NAME, "Apache Tuscany SCA");
+        props.put(PRODUCT_VERSION, "2.0.0");
+        props.put(VENDOR_NAME, "Apache Software Foundation");
+        return props;
+    }
 }

Modified: tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java?rev=789859&r1=789858&r2=789859&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java (original)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java Tue Jun 30 18:08:11 2009
@@ -6,33 +6,49 @@
  * 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.    
+ * under the License.
  */
 
 package org.apache.tuscany.sca.implementation.osgi.runtime;
 
+import org.apache.tuscany.sca.dosgi.discovery.DiscoveryActivator;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.distribution.DistributionProvider;
 
 /**
  * Bundle activator to receive the BundleContext
  */
 public class OSGiImplementationRuntimeActivator implements BundleActivator {
     private static BundleContext bundleContext;
+    private DiscoveryActivator discoveryActivator;
+    private ServiceRegistration distributionProvider;
 
     public void start(BundleContext context) throws Exception {
         bundleContext = context;
+        discoveryActivator = new DiscoveryActivator();
+        discoveryActivator.start(context);
+        OSGiDistributionProvider provider = new OSGiDistributionProvider(bundleContext);
+        distributionProvider = bundleContext.registerService(DistributionProvider.class.getName(), provider, provider.getProperties());
     }
 
     public void stop(BundleContext context) throws Exception {
+        if (discoveryActivator != null) {
+            discoveryActivator.stop(context);
+        }
+        if (distributionProvider != null) {
+            distributionProvider.unregister();
+        }
+        discoveryActivator = null;
         bundleContext = null;
     }
 

Modified: tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java?rev=789859&r1=789858&r2=789859&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java (original)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java Tue Jun 30 18:08:11 2009
@@ -6,15 +6,15 @@
  * 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.    
+ * under the License.
  */
 
 package org.apache.tuscany.sca.implementation.osgi.runtime;
@@ -26,7 +26,6 @@
 import java.util.Hashtable;
 import java.util.List;
 
-import org.apache.tuscany.sca.core.factory.InstanceWrapper;
 import org.apache.tuscany.sca.interfacedef.DataType;
 import org.apache.tuscany.sca.interfacedef.Interface;
 import org.apache.tuscany.sca.interfacedef.Operation;
@@ -42,13 +41,12 @@
 /**
  * The Invoker looks up the corresponding OSGi service from the OSGi service registry
  * and delegate the call to it.
- *  
+ *
  * @version $Rev$ $Date$
  */
-public class OSGiTargetInvoker<T> implements Invoker {
+public class OSGiTargetInvoker implements Invoker {
 
     private Operation operation;
-    protected InstanceWrapper<T> target;
 
     private final OSGiImplementationProvider provider;
     private final RuntimeComponent component;
@@ -175,7 +173,7 @@
 
     /**
      * Return the method on the implementation class that matches the operation.
-     * 
+     *
      * @param implClass the implementation class or interface
      * @param operation the operation to match
      * @return the method described by the operation
@@ -197,7 +195,7 @@
                 }
             }
 
-            // TUSCANY-2180 If there is only one method then we just match on the name 
+            // TUSCANY-2180 If there is only one method then we just match on the name
             // (this is the same as the existing behaviour)
             if (matchingMethods.size() == 1) {
                 return matchingMethods.get(0);

Added: tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/distribution/DistributionProvider.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/distribution/DistributionProvider.java?rev=789859&view=auto
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/distribution/DistributionProvider.java (added)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/distribution/DistributionProvider.java Tue Jun 30 18:08:11 2009
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) OSGi Alliance (2000, 2008). All Rights Reserved.
+ *
+ * Licensed 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.osgi.service.distribution;
+
+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.
+ *
+ * @ThreadSafe
+ * @version $Revision$
+ */
+public interface DistributionProvider {
+    /**
+     * Service Registration property for the name of the Distribution Provider
+     * product.
+     * <p>
+     * The value of this property is of type String.
+     */
+    static final String PRODUCT_NAME = "osgi.remote.distribution.product";
+
+    /**
+     * Service Registration property for the version of the Distribution
+     * Provider product.
+     * <p>
+     * The value of this property is of type String.
+     */
+    static final String PRODUCT_VERSION = "osgi.remote.distribution.product.version";
+
+    /**
+     * Service Registration property for the Distribution Provider product
+     * vendor name.
+     * <p>
+     * The value of this property is of type String.
+     */
+    static final String VENDOR_NAME = "osgi.remote.distribution.vendor";
+
+    /**
+     * Service Registration property that lists the intents supported by this
+     * DistributionProvider.
+     * <p>
+     * The value of this property is of type String, String[] or Collection of
+     * String.
+     */
+    static final String 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 /*<? extends 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 /*<? extends 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 serviceosgi.intents="transactionality" is set. However, these
+     * intents are <i>not</i> 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);
+}