You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gn...@apache.org on 2012/07/26 16:49:42 UTC

svn commit: r1366025 - /felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java

Author: gnodet
Date: Thu Jul 26 14:49:42 2012
New Revision: 1366025

URL: http://svn.apache.org/viewvc?rev=1366025&view=rev
Log:
[FELIX-3609] Add back a fixed version for keeping hooks sorted

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

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java?rev=1366025&r1=1366024&r2=1366025&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java Thu Jul 26 14:49:42 2012
@@ -488,6 +488,7 @@ public class ServiceRegistry
 
     void servicePropertiesModified(ServiceRegistration reg, Dictionary oldProps)
     {
+        updateHook(reg.getReference());
         if (m_callbacks != null)
         {
             m_callbacks.serviceChanged(
@@ -704,7 +705,7 @@ public class ServiceRegistry
                     Set<ServiceReference<?>> hooks = m_allHooks.get(hookClass);
                     if (hooks == null)
                     {
-                        hooks = new HashSet<ServiceReference<?>>();
+                        hooks = new TreeSet<ServiceReference<?>>(Collections.reverseOrder());
                         m_allHooks.put(hookClass, hooks);
                     }
                     hooks.add(ref);
@@ -713,6 +714,32 @@ public class ServiceRegistry
         }
     }
 
+    private void updateHook(ServiceReference ref)
+    {
+        // We maintain the hooks sorted, so if ranking has changed for example,
+        // we need to ensure the order remains correct by resorting the hooks.
+        Object svcObj = ((ServiceRegistrationImpl.ServiceReferenceImpl) ref)
+                .getRegistration().getService();
+        String [] classNames = (String[]) ref.getProperty(Constants.OBJECTCLASS);
+
+        for (Class<?> hookClass : m_hookClasses)
+        {
+            if (isHook(classNames, hookClass, svcObj))
+            {
+                synchronized (m_allHooks)
+                {
+                    Set<ServiceReference<?>> hooks = m_allHooks.get(hookClass);
+                    if (hooks != null)
+                    {
+                        List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>(hooks);
+                        hooks.clear();
+                        hooks.addAll(refs);
+                    }
+                }
+            }
+        }
+    }
+
     private void removeHook(ServiceReference ref)
     {
         Object svcObj = ((ServiceRegistrationImpl.ServiceReferenceImpl) ref)