[FELIX-3609] Add back a fixed version for keeping hooks sorted
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1366025 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java b/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
index c21ba5b..b604de2 100644
--- a/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
+++ b/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
@@ -488,6 +488,7 @@
void servicePropertiesModified(ServiceRegistration reg, Dictionary oldProps)
{
+ updateHook(reg.getReference());
if (m_callbacks != null)
{
m_callbacks.serviceChanged(
@@ -704,7 +705,7 @@
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 @@
}
}
+ 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)