Added some patches suggested by Karl Pauls to fix a specification compliance
issue where null was not properly being returned after a service was
unregistered. When removing all service registrations for a bundle, the
framework not explicitly calls unregister() on each one.
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@371609 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
index b10b595..5f52889 100644
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/ServiceRegistrationImpl.java
@@ -91,9 +91,12 @@
public void unregister()
{
- m_registry.unregisterService(m_bundle, this);
- m_svcObj = null;
- m_factory = null;
+ if (m_svcObj != null)
+ {
+ m_registry.unregisterService(m_bundle, this);
+ m_svcObj = null;
+ m_factory = null;
+ }
}
//
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 539d994..e53b932 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
@@ -77,9 +77,16 @@
ServiceRegistration[] regs = (ServiceRegistration[]) m_serviceRegsMap.get(bundle);
m_serviceRegsMap.put(bundle, removeServiceRegistration(regs, reg));
}
+
fireServiceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, reg.getReference()));
}
+ /**
+ * This method retrieves all services registrations for the specified
+ * bundle and invokes <tt>ServiceRegistration.unregister()</tt> on each
+ * one.
+ * @param bundle the bundle whose services should be unregistered.
+ **/
public void unregisterServices(Bundle bundle)
{
// Simply remove all service registrations for the bundle.
@@ -87,14 +94,12 @@
synchronized (this)
{
regs = (ServiceRegistration[]) m_serviceRegsMap.get(bundle);
- m_serviceRegsMap.remove(bundle);
}
- // Fire all events outside of synchronized block.
+ // Unregister each service.
for (int i = 0; (regs != null) && (i < regs.length); i++)
{
- fireServiceChanged(
- new ServiceEvent(ServiceEvent.UNREGISTERING, regs[i].getReference()));
+ regs[i].unregister();
}
}