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 250b7bc91a FELIX-6616 : reduce timing window for binding dynamic 
greedy refs
     new f1f5bc7c26 Merge pull request #214 from tjwatson/FELIX-6616
250b7bc91a is described below

commit 250b7bc91a1e074d17bda846a4b17cc87f5391d1
Author: Thomas Watson <[email protected]>
AuthorDate: Mon Jul 17 10:46:20 2023 -0500

    FELIX-6616 : reduce timing window for binding dynamic greedy refs
    
    For 1..1 and 0..1 dynamic greedy references it is possible that
    the activating thread will bind a lower ranked service while
    another thead is binding a higher ranked service.  This can
    result in some strange orders for bind methods.
    
    This change reduces the timing window such that the activating
    thread will immediately bind the higher ranked service as long
    as another thread has indicated that it will bind the higher
    ranked service. This still results in some extra bind calls
    for the same higher ranked service but greatly reduces the
    window where the activating thread will bind a lower ranked
    service while the tracking thread is trying to bind a higher
    ranked service.
    
    This change moves the check for what ref to bind from the
    activating thread to just before it will call bind on the
    component object being activated. There is still a small
    window where another thread may register a higher ranked
    service right after the activating thread gets the ref
    to bind and when it actually calls bind. If this proves
    to be problematic then we may need an additional check
    after bind during activate that makes sure the latest
    tracked service is what actually got bound during activate.
---
 .../org/apache/felix/scr/impl/manager/DependencyManager.java  | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git 
a/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java 
b/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
index 2ce9c6386d..813c8230d3 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
@@ -957,8 +957,8 @@ public class DependencyManager<S, T> implements 
ReferenceManager<S, T>
             {
                 boolean invokedUnbind = false;
                 m_componentManager.invokeBindMethod(DependencyManager.this,
-                    bindingRefPair, trackingCount);
-                if (!bindingRefPair.isFailed())
+                    refPair, trackingCount);
+                if (!refPair.isFailed())
                 {
                     if (current != null)
                     {
@@ -971,7 +971,7 @@ public class DependencyManager<S, T> implements 
ReferenceManager<S, T>
                 else if (cardinalitySatisfied(0))
                 {
                     
m_componentManager.registerMissingDependency(DependencyManager.this,
-                        bindingRefPair.getRef(), trackingCount);
+                        refPair.getRef(), trackingCount);
                 }
                 RefPair<S, T> next = null;
                 synchronized (monitor)
@@ -1210,9 +1210,10 @@ public class DependencyManager<S, T> implements 
ReferenceManager<S, T>
                 synchronized (monitor)
                 {
                     trackingCount.set(this.trackingCount);
-                    return currentRefPair == null
+                    RefPair<S, T> current = bindingRefPair != null ? 
bindingRefPair : currentRefPair;
+                    return current == null
                         ? Collections.<RefPair<S, T>> emptyList()
-                        : Collections.singleton(currentRefPair);
+                        : Collections.singleton(current);
                 }
             }
             else

Reply via email to