felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1614660 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework: BundleContextImpl.java ServiceRegistrationImpl.java
Date Wed, 30 Jul 2014 13:36:40 GMT
Author: cziegeler
Date: Wed Jul 30 13:36:39 2014
New Revision: 1614660

URL: http://svn.apache.org/r1614660
Log:
FELIX-4505 : [Core R6] Support Prototype Service Factory - inital version supporting ServiceObjects
for singleton and bundle scope

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java?rev=1614660&r1=1614659&r2=1614660&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
Wed Jul 30 13:36:39 2014
@@ -531,9 +531,46 @@ class BundleContextImpl implements Felix
      */
     public <S> ServiceObjects<S> getServiceObjects(final ServiceReference<S>
ref)
     {
-        // Get the service registration.
-        final ServiceRegistrationImpl reg =
-            ((ServiceRegistrationImpl.ServiceReferenceImpl) ref).getRegistration();
-        return reg.getServiceObjects(m_bundle);
+        return new ServiceObjectsImpl(ref);
     }
+
+    //
+    // ServiceObjects implementation
+    //
+    class ServiceObjectsImpl<S> implements ServiceObjects<S>
+    {
+        private final ServiceReference<S> m_ref;
+
+        public ServiceObjectsImpl(final ServiceReference<S> ref)
+        {
+            this.m_ref = ref;
+        }
+
+        public S getService() {
+            // special handling for prototype scope
+            if ( m_ref.getProperty(Constants.SERVICE_SCOPE) == Constants.SCOPE_PROTOTYPE
)
+            {
+                throw new UnsupportedOperationException();
+            }
+            // getService handles singleton and bundle scope
+            return BundleContextImpl.this.getService(m_ref);
+        }
+
+        public void ungetService(final S service)
+        {
+            // special handling for prototype scope
+            if ( m_ref.getProperty(Constants.SERVICE_SCOPE) == Constants.SCOPE_PROTOTYPE
)
+            {
+                throw new UnsupportedOperationException();
+            }
+            // ungetService handles singleton and bundle scope
+            BundleContextImpl.this.ungetService(m_ref);
+        }
+
+        public ServiceReference<S> getServiceReference()
+        {
+            return m_ref;
+        }
+    }
+
 }
\ No newline at end of file

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java?rev=1614660&r1=1614659&r2=1614660&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
Wed Jul 30 13:36:39 2014
@@ -36,9 +36,9 @@ import org.apache.felix.framework.wiring
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleReference;
 import org.osgi.framework.Constants;
+import org.osgi.framework.PrototypeServiceFactory;
 import org.osgi.framework.ServiceException;
 import org.osgi.framework.ServiceFactory;
-import org.osgi.framework.ServiceObjects;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.framework.wiring.BundleCapability;
@@ -60,7 +60,7 @@ class ServiceRegistrationImpl implements
     // Service factory interface.
     private volatile ServiceFactory m_factory;
     // Associated property dictionary.
-    private volatile Map m_propMap = new StringMap();
+    private volatile Map<String, Object> m_propMap = new StringMap();
     // Re-usable service reference.
     private final ServiceReferenceImpl m_ref;
     // Flag indicating that we are unregistering.
@@ -293,18 +293,18 @@ class ServiceRegistrationImpl implements
         }
     }
 
-    private void initializeProperties(Dictionary dict)
+    private void initializeProperties(Dictionary<String, Object> dict)
     {
         // Create a case-insensitive map for the properties.
-        Map props = new StringMap();
+        Map<String, Object> props = new StringMap();
 
         if (dict != null)
         {
             // Make sure there are no duplicate keys.
-            Enumeration keys = dict.keys();
+            Enumeration<String> keys = dict.keys();
             while (keys.hasMoreElements())
             {
-                Object key = keys.nextElement();
+                String key = keys.nextElement();
                 if (props.get(key) == null)
                 {
                     props.put(key, dict.get(key));
@@ -320,6 +320,16 @@ class ServiceRegistrationImpl implements
         props.put(Constants.OBJECTCLASS, m_classes);
         props.put(Constants.SERVICE_ID, m_serviceId);
         props.put(Constants.SERVICE_BUNDLEID, m_bundle.getBundleId());
+        if ( m_factory != null )
+        {
+            props.put(Constants.SERVICE_SCOPE,
+                      (m_factory instanceof PrototypeServiceFactory
+                       ? Constants.SCOPE_PROTOTYPE : Constants.SCOPE_BUNDLE));
+        }
+        else
+        {
+            props.put(Constants.SERVICE_SCOPE, Constants.SCOPE_SINGLETON);
+        }
 
         // Update the service property map.
         m_propMap = props;
@@ -404,14 +414,6 @@ class ServiceRegistrationImpl implements
         }
     }
 
-    /**
-     * Get the service objects for the provided bundle
-     */
-    public ServiceObjects getServiceObjects(Bundle bundle)
-    {
-        throw new UnsupportedOperationException();
-    }
-
     //
     // ServiceReference implementation
     //



Mime
View raw message