Modified service unregistration to forcibly unget the service object
from all clients if they did not do so themselves in response to the
unregistering event.


git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@420907 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
index f65e9be..e60e9ad 100644
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
@@ -72,13 +72,27 @@
 
     public void unregisterService(Bundle bundle, ServiceRegistration reg)
     {
+        // First remove the registered service.
         synchronized (this)
         {
             ServiceRegistration[] regs = (ServiceRegistration[]) m_serviceRegsMap.get(bundle);
             m_serviceRegsMap.put(bundle, removeServiceRegistration(regs, reg));
         }
 
+        // Fire the service event which gives all client bundles the
+        // opportunity to unget their service object.
         fireServiceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, reg.getReference()));
+
+        // Now forcibly unget the service object for all stubborn clients.
+        synchronized (this)
+        {
+            Bundle[] clients = getUsingBundles(reg.getReference());
+            for (int i = 0; (clients != null) && (i < clients.length); i++)
+            {
+                while (ungetService(clients[i], reg.getReference()))
+                    ; // Keep removing until it is no longer possible
+            }
+        }
     }
 
     /**