amichair commented on code in PR #95:
URL: https://github.com/apache/aries-rsa/pull/95#discussion_r3170443692


##########
rsa/src/main/java/org/apache/aries/rsa/core/event/EventAdminSender.java:
##########
@@ -18,85 +18,148 @@
  */
 package org.apache.aries.rsa.core.event;
 
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.security.cert.X509Certificate;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Version;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventAdmin;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.ExportReference;
 import org.osgi.service.remoteserviceadmin.ImportReference;
 import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class EventAdminSender {
-    private HashMap<Integer, String> typeToTopic;
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(EventAdminSender.class);
+
     private BundleContext context;
 
     public EventAdminSender(BundleContext context) {
         this.context = context;
-        typeToTopic = new HashMap<>();
-        typeToTopic.put(RemoteServiceAdminEvent.EXPORT_ERROR, "EXPORT_ERROR");
-        typeToTopic.put(RemoteServiceAdminEvent.EXPORT_REGISTRATION, 
"EXPORT_REGISTRATION");
-        typeToTopic.put(RemoteServiceAdminEvent.EXPORT_UNREGISTRATION, 
"EXPORT_UNREGISTRATION");
-        typeToTopic.put(RemoteServiceAdminEvent.EXPORT_UPDATE, 
"EXPORT_UPDATE");
-        typeToTopic.put(RemoteServiceAdminEvent.EXPORT_WARNING, 
"EXPORT_WARNING");
-        typeToTopic.put(RemoteServiceAdminEvent.IMPORT_ERROR, "IMPORT_ERROR");
-        typeToTopic.put(RemoteServiceAdminEvent.IMPORT_REGISTRATION, 
"IMPORT_REGISTRATION");
-        typeToTopic.put(RemoteServiceAdminEvent.IMPORT_UNREGISTRATION, 
"IMPORT_UNREGISTRATION");
-        typeToTopic.put(RemoteServiceAdminEvent.IMPORT_UPDATE, 
"IMPORT_UPDATE");
-        typeToTopic.put(RemoteServiceAdminEvent.IMPORT_WARNING, 
"IMPORT_WARNING");
     }
 
-    public void send(RemoteServiceAdminEvent rsaEvent) {
-        final Event event = toEvent(rsaEvent);
-        ServiceReference<EventAdmin> sref = 
this.context.getServiceReference(EventAdmin.class);
+    private void notifyEventAdmins(String type, Event event) {
+        // according to the EventAdmin specs, we publish to the service with 
the
+        // highest ranking (which is the one returned by getServiceReference)
+        ServiceReference<EventAdmin> sref = 
context.getServiceReference(EventAdmin.class);
         if (sref != null) {
-            final EventAdmin eventAdmin = this.context.getService(sref);
-            AccessController.doPrivileged(new PrivilegedAction<Void>() {
-                public Void run() {
-                    eventAdmin.postEvent(event);
-                    return null;
+            LOG.debug("Publishing event {} to EventAdmin", type);
+            final EventAdmin eventAdmin = context.getService(sref);
+            if (eventAdmin != null) {
+                try {
+                    AccessController.doPrivileged((PrivilegedAction<Void>) () 
-> {
+                        eventAdmin.postEvent(event);
+                        return null;
+                    });
+                } finally {
+                    context.ungetService(sref);

Review Comment:
   oops it got messed up when resolving conflicts when rewriting git history to 
organize the commits into a PR... originally there was just the outer one, and 
I moved it a finally block, but the original sneaked back in. Good thing you 
caught it!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to