felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1703163 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework: Felix.java HookRegistry.java
Date Tue, 15 Sep 2015 11:58:03 GMT
Author: cziegeler
Date: Tue Sep 15 11:58:03 2015
New Revision: 1703163

URL: http://svn.apache.org/r1703163
Log:
FELIX-5034 : Reduce and correct locking related to the hook registry

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

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java?rev=1703163&r1=1703162&r2=1703163&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java Tue Sep 15 11:58:03
2015
@@ -3112,7 +3112,7 @@ public class Felix extends BundleImpl im
         if (existing != null)
         {
             Set<ServiceReference<org.osgi.framework.hooks.bundle.FindHook>> hooks
=
-                    getHookRegistry().getBundleFindHooks();
+                    getHookRegistry().getHooks(org.osgi.framework.hooks.bundle.FindHook.class);
             if (!hooks.isEmpty())
             {
                 Collection<Bundle> bundles = new ArrayList<Bundle>(1);
@@ -3206,7 +3206,7 @@ public class Felix extends BundleImpl im
         }
 
         Set<ServiceReference<org.osgi.framework.hooks.bundle.FindHook>> hooks
=
-                getHookRegistry().getBundleFindHooks();
+                getHookRegistry().getHooks(org.osgi.framework.hooks.bundle.FindHook.class);
         if (!hooks.isEmpty() && (bundle != null))
         {
             Collection<Bundle> bundles = new ArrayList<Bundle>(1);
@@ -3285,7 +3285,7 @@ public class Felix extends BundleImpl im
         if ( !bundles.isEmpty() && bc.getBundle() != this )
         {
             Set<ServiceReference<org.osgi.framework.hooks.bundle.FindHook>> hooks
=
-                    getHookRegistry().getBundleFindHooks();
+                    getHookRegistry().getHooks(org.osgi.framework.hooks.bundle.FindHook.class);
             if (!hooks.isEmpty())
             {
                 Collection<Bundle> shrunkBundles = new ShrinkableCollection<Bundle>(new
ArrayList<Bundle>(bundles));
@@ -3359,7 +3359,7 @@ public class Felix extends BundleImpl im
 
         // Invoke ListenerHook.removed() if filter updated.
         Set<ServiceReference<org.osgi.framework.hooks.service.ListenerHook>>
listenerHooks =
-                getHookRegistry().getServiceListenerHooks();
+                getHookRegistry().getHooks(org.osgi.framework.hooks.service.ListenerHook.class);
         if (oldFilter != null)
         {
             final Collection removed = Collections.singleton(
@@ -3430,7 +3430,7 @@ public class Felix extends BundleImpl im
         {
             // Invoke the ListenerHook.removed() on all hooks.
             Set<ServiceReference<org.osgi.framework.hooks.service.ListenerHook>>
listenerHooks =
-                    getHookRegistry().getServiceListenerHooks();
+                    getHookRegistry().getHooks(org.osgi.framework.hooks.service.ListenerHook.class);
             Collection removed = Collections.singleton(listener);
             for (ServiceReference<org.osgi.framework.hooks.service.ListenerHook> sr
: listenerHooks)
             {
@@ -3601,7 +3601,7 @@ public class Felix extends BundleImpl im
 
         // activate findhooks
         Set<ServiceReference<org.osgi.framework.hooks.service.FindHook>> findHooks
=
-                getHookRegistry().getServiceFindHooks();
+                getHookRegistry().getHooks(org.osgi.framework.hooks.service.FindHook.class);
         for (ServiceReference<org.osgi.framework.hooks.service.FindHook> sr : findHooks)
         {
             org.osgi.framework.hooks.service.FindHook fh = getService(this, sr, false);

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/HookRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/HookRegistry.java?rev=1703163&r1=1703162&r2=1703163&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/HookRegistry.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/HookRegistry.java Tue Sep
15 11:58:03 2015
@@ -25,6 +25,7 @@ import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
 import java.util.WeakHashMap;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceFactory;
@@ -59,7 +60,7 @@ public class HookRegistry
     }
 
     private final Map<String, SortedSet<ServiceReference<?>>> m_allHooks
=
-        new HashMap<String, SortedSet<ServiceReference<?>>>();
+        new ConcurrentHashMap<String, SortedSet<ServiceReference<?>>>();
 
     private final WeakHashMap<ServiceReference<?>, ServiceReference<?>>
m_blackList =
             new WeakHashMap<ServiceReference<?>, ServiceReference<?>>();
@@ -119,7 +120,7 @@ public class HookRegistry
         {
             if (isHook(serviceName, svcObj))
             {
-                synchronized (m_allHooks)
+                synchronized (m_allHooks) // we need to sync as we replace the value
                 {
                     SortedSet<ServiceReference<?>> hooks = m_allHooks.get(serviceName);
                     if (hooks == null)
@@ -153,7 +154,7 @@ public class HookRegistry
         {
             if (isHook(serviceName, svcObj))
             {
-                synchronized (m_allHooks)
+                synchronized (m_allHooks) // we need to sync as we replace the value
                 {
                     SortedSet<ServiceReference<?>> hooks = m_allHooks.get(serviceName);
                     if (hooks != null)
@@ -180,7 +181,7 @@ public class HookRegistry
         {
             if (isHook(serviceName, svcObj))
             {
-                synchronized (m_allHooks)
+                synchronized (m_allHooks) // we need to sync as we replace the value
                 {
                     SortedSet<ServiceReference<?>> hooks = m_allHooks.get(serviceName);
                     if (hooks != null)
@@ -214,26 +215,6 @@ public class HookRegistry
         return Collections.emptySet();
     }
 
-    public Set<ServiceReference<org.osgi.framework.hooks.bundle.FindHook>> getBundleFindHooks()
-    {
-        return getHooks(org.osgi.framework.hooks.bundle.FindHook.class);
-    }
-
-    public Set<ServiceReference<org.osgi.framework.hooks.service.FindHook>> getServiceFindHooks()
-    {
-        return getHooks(org.osgi.framework.hooks.service.FindHook.class);
-    }
-
-    public Set<ServiceReference<org.osgi.framework.hooks.bundle.EventHook>> getBundleEventHooks()
-    {
-        return getHooks(org.osgi.framework.hooks.bundle.EventHook.class);
-    }
-
-    public Set<ServiceReference<org.osgi.framework.hooks.service.ListenerHook>>
getServiceListenerHooks()
-    {
-        return getHooks(org.osgi.framework.hooks.service.ListenerHook.class);
-    }
-
     public boolean isHookBlackListed(final ServiceReference<?> sr)
     {
         synchronized ( m_blackList )
@@ -249,5 +230,4 @@ public class HookRegistry
             m_blackList.put(sr, sr);
         }
     }
-
 }



Mime
View raw message