You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2015/02/26 11:42:19 UTC

[3/4] karaf git commit: [KARAF-3257] Do not hide events for services registered before the service guard

[KARAF-3257] Do not hide events for services registered before the service guard


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/fbf557b1
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/fbf557b1
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/fbf557b1

Branch: refs/heads/karaf-2.x
Commit: fbf557b1ff7e31b614d35f513313f5c5f39d6d92
Parents: 73e57b8
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Tue Oct 28 13:40:57 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Thu Feb 26 11:38:57 2015 +0100

----------------------------------------------------------------------
 .../karaf/service/guard/impl/GuardingEventHook.java  | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/fbf557b1/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardingEventHook.java
----------------------------------------------------------------------
diff --git a/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardingEventHook.java b/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardingEventHook.java
index a37e863..356d654 100644
--- a/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardingEventHook.java
+++ b/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardingEventHook.java
@@ -23,12 +23,15 @@ import org.osgi.framework.hooks.service.ListenerHook;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentSkipListSet;
 
 public class GuardingEventHook implements EventListenerHook {
 
     private final BundleContext bundleContext;
     private final GuardProxyCatalog guardProxyCatalog;
     private final Filter servicesFilter;
+    private final Set<ServiceReference<?>> references = new ConcurrentSkipListSet<ServiceReference<?>>();
 
     GuardingEventHook(BundleContext bundleContext, GuardProxyCatalog guardProxyCatalog, Filter securedServicesFilter) throws InvalidSyntaxException {
         this.bundleContext = bundleContext;
@@ -47,6 +50,18 @@ public class GuardingEventHook implements EventListenerHook {
             return;
         }
 
+        if (event.getType() == ServiceEvent.REGISTERED) {
+            references.add(sr);
+        } else if (event.getType() == ServiceEvent.UNREGISTERING) {
+            if (!references.remove(sr)) {
+                return;
+            }
+        } else {
+            if (!references.contains(sr)) {
+                return;
+            }
+        }
+
         for (Iterator<BundleContext> i = listeners.keySet().iterator(); i.hasNext(); ) {
             BundleContext bc = i.next();
             if (bundleContext.equals(bc) || bc.getBundle().getBundleId() == 0L) {