felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1397396 - /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
Date Fri, 12 Oct 2012 00:40:23 GMT
Author: djencks
Date: Fri Oct 12 00:40:23 2012
New Revision: 1397396

URL: http://svn.apache.org/viewvc?rev=1397396&view=rev
Log:
FELIX-3680 don't drop service events when enabling

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java?rev=1397396&r1=1397395&r2=1397396&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
Fri Oct 12 00:40:23 2012
@@ -21,12 +21,14 @@ package org.apache.felix.scr.impl.manage
 
 import java.security.Permission;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
 import org.apache.felix.scr.Component;
 import org.apache.felix.scr.Reference;
 import org.apache.felix.scr.impl.BundleComponentActivator;
@@ -73,6 +75,8 @@ public class DependencyManager implement
     // the target service filter
     private volatile Filter m_targetFilter;
 
+    private final Collection<ServiceReference> added = new ArrayList<ServiceReference>();
+
 
     /**
      * Constructor that receives several parameters.
@@ -130,8 +134,17 @@ public class DependencyManager implement
                     // consider the service if the filter matches
                     if ( targetFilterMatch( ref ) )
                     {
-                        m_size++;
-                        serviceAdded( ref );
+                        added.add( ref );
+                        synchronized (added)
+                        {
+                            //wait for enable to complete
+                        }
+                        if (added.contains( ref ))
+                        {
+                            added.remove( ref );
+                            m_size++;
+                            serviceAdded( ref );
+                        }
                     }
                     else
                     {
@@ -547,13 +560,24 @@ public class DependencyManager implement
 
         if ( hasGetPermission() )
         {
-            // get the current number of registered services available
-            ServiceReference refs[] = getFrameworkServiceReferences();
-            m_size = ( refs == null ) ? 0 : refs.length;
-
-            // register the service listener
-            String filterString = "(" + Constants.OBJECTCLASS + "=" + m_dependencyMetadata.getInterface()
+ ")";
-            m_componentManager.getActivator().getBundleContext().addServiceListener( this,
filterString );
+            synchronized ( added )
+            {
+                // register the service listener
+                String filterString = "(" + Constants.OBJECTCLASS + "=" + m_dependencyMetadata.getInterface()
+ ")";
+                m_componentManager.getActivator().getBundleContext().addServiceListener(
this, filterString );
+
+                // get the current number of registered services available
+                ServiceReference refs[] = getFrameworkServiceReferences();
+                if (refs != null)
+                {
+                    for (ServiceReference ref: refs)
+                    {
+                        added.remove( ref );
+                    }
+                }
+                m_size = ( refs == null ) ? 0 : refs.length;
+            }
+
 
             m_componentManager.log( LogService.LOG_DEBUG,
                 "Registered for service events, currently {0} service(s) match the filter",
new Object[]
@@ -565,8 +589,8 @@ public class DependencyManager implement
             m_size = 0;
 
             m_componentManager.log( LogService.LOG_DEBUG,
-                "Not registered for service events since the bundle has no permission to
get service {0}", new Object[]
-                    { m_dependencyMetadata.getInterface() }, null );
+                    "Not registered for service events since the bundle has no permission
to get service {0}", new Object[]
+                    {m_dependencyMetadata.getInterface()}, null );
         }
     }
 
@@ -1256,7 +1280,7 @@ public class DependencyManager implement
             // if the component instance has already been cleared by the
             // close() method
             m_componentManager.log( LogService.LOG_DEBUG,
-                "DependencyManager : Component not set, no need to call updated method",
null );
+                    "DependencyManager : Component not set, no need to call updated method",
null );
         }
     }
 



Mime
View raw message