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

amichair pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-rsa.git

commit 86144b249af5785b75c313f4dd90585488fd02cb
Author: Amichai Rothman <[email protected]>
AuthorDate: Fri May 22 23:35:11 2026 +0300

    Fix EventListenerBridge missing previously registered consumers
---
 .../org/apache/aries/rsa/core/EventListenerBridge.java  | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git 
a/rsa/src/main/java/org/apache/aries/rsa/core/EventListenerBridge.java 
b/rsa/src/main/java/org/apache/aries/rsa/core/EventListenerBridge.java
index 8d43a0c0..719cfb14 100644
--- a/rsa/src/main/java/org/apache/aries/rsa/core/EventListenerBridge.java
+++ b/rsa/src/main/java/org/apache/aries/rsa/core/EventListenerBridge.java
@@ -171,7 +171,7 @@ public class EventListenerBridge implements 
ServiceListener, ListenerHook {
     private final Map<Long, Integer> producers = new ConcurrentHashMap<>(); // 
bundleId to producer types bitmap
 
     private final BundleContext context;
-    private ServiceRegistration<ServiceFactory<Adapter>> factoryRegistration;
+    private volatile ServiceRegistration<ServiceFactory<Adapter>> 
factoryRegistration;
     private ServiceRegistration<ListenerHook> hookRegistration;
 
     public EventListenerBridge(BundleContext context) {
@@ -215,11 +215,18 @@ public class EventListenerBridge implements 
ServiceListener, ListenerHook {
 
     @SuppressWarnings("unchecked")
     public void start() throws InvalidSyntaxException {
-        // ServiceListener to track consumers
+        // add ServiceListener to track new/updated consumers
         context.addServiceListener(this, SERVICE_LISTENER_FILTER);
-        // ListenerHook to track what producers are looking for
+        // process previously registered consumers
+        ServiceReference<?>[] existing = 
context.getServiceReferences((String)null, SERVICE_LISTENER_FILTER);
+        if (existing != null) {
+            for (ServiceReference<?> sref : existing) {
+                serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, 
sref));
+            }
+        }
+        // register ListenerHook to track what producers are looking for
         hookRegistration = context.registerService(ListenerHook.class, this, 
null);
-        // our listener, backed by a ServiceFactory, to be used by producers
+        // register our listener, backed by a ServiceFactory, to be used by 
producers
         factoryRegistration = (ServiceRegistration<ServiceFactory<Adapter>>)
             context.registerService(
                 new String[] { ENDPOINT_LISTENER_CLASS_NAME, 
ENDPOINT_EVENT_LISTENER_CLASS_NAME },
@@ -268,7 +275,7 @@ public class EventListenerBridge implements 
ServiceListener, ListenerHook {
         else if (!el) // only EEL (not EL)
             modified |= 
newConsumers.add((ServiceReference<EndpointEventListener>)sref);
         // update our own listener's scopes accordingly
-        if (modified) {
+        if (modified && factoryRegistration != null) {
             factoryRegistration.setProperties(getListenerProperties());
         }
     }

Reply via email to