This is an automated email from the ASF dual-hosted git repository.

tjwatson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new 29b07db15e FELIX-6667 - Reresoliving hosts or resolving new fragments 
does not invalidate meta-data cache for SCR
     new 6eda791006 Merge pull request #242 from tjwatson/FELIX-6667
29b07db15e is described below

commit 29b07db15e3f62162e993c2ba225251c5629cf69
Author: Thomas Watson <[email protected]>
AuthorDate: Wed Nov 1 09:37:19 2023 -0500

    FELIX-6667 - Reresoliving hosts or resolving new fragments does not 
invalidate meta-data cache for SCR
    
    This fix detects the UNRESOLVED event in addition to the UPDATED
    and UNINSTALLED events to remove the meta-data cache for a bundle.
    Additionally, this fix detects cases where a fragment is resolved
    and dynamically attached to a host. In this case it also removes
    the host meta-data cache.
---
 .../java/org/apache/felix/scr/impl/Activator.java  | 24 ++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java 
b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
index 0cfde4ea08..f54e70f7ca 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
@@ -58,6 +58,7 @@ import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.namespace.HostNamespace;
 import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.framework.wiring.BundleWire;
 import org.osgi.framework.wiring.BundleWiring;
@@ -253,11 +254,30 @@ public class Activator extends AbstractExtender
     public void bundleChanged(BundleEvent event)
     {
         super.bundleChanged(event);
-        if (event.getType() == BundleEvent.UPDATED
-            || event.getType() == BundleEvent.UNINSTALLED)
+        int eType = event.getType();
+        if (eType == BundleEvent.UPDATED
+            || eType == BundleEvent.UNINSTALLED
+            || eType == BundleEvent.UNRESOLVED)
         {
             m_componentMetadataStore.remove(event.getBundle().getBundleId());
         }
+        if (eType == BundleEvent.RESOLVED)
+        {
+            BundleRevision revision = 
event.getBundle().adapt(BundleRevision.class);
+            if (revision != null && (revision.getTypes() & 
BundleRevision.TYPE_FRAGMENT) == BundleRevision.TYPE_FRAGMENT)
+            {
+                BundleWiring wiring = revision.getWiring();
+                List<BundleWire> hostWires = wiring != null ? 
wiring.getRequiredWires(HostNamespace.HOST_NAMESPACE) : null;
+                if (hostWires != null && !hostWires.isEmpty())
+                {
+                    for (BundleWire hostWire : hostWires)
+                    {
+                        // invalidate any hosts of newly resolved fragments
+                        
m_componentMetadataStore.remove(hostWire.getProvider().getBundle().getBundleId());
+                    }
+                }
+            }
+        }
     }
 
     private static ConcurrentMap<Long, List<ComponentMetadata>> load(

Reply via email to