Fix blueprint event handling
[controller.git] / opendaylight / blueprint / src / main / java / org / opendaylight / controller / blueprint / BlueprintBundleTracker.java
index 5119c90363794b2b71334e3fc4ac17d1e2d8ae29..08a8da0bb6d98575be91098e124ce85fe239a35f 100644 (file)
@@ -31,9 +31,8 @@ import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.framework.SynchronousBundleListener;
 import org.osgi.service.blueprint.container.BlueprintContainer;
-import org.osgi.service.blueprint.container.EventConstants;
-import org.osgi.service.event.Event;
-import org.osgi.service.event.EventHandler;
+import org.osgi.service.blueprint.container.BlueprintEvent;
+import org.osgi.service.blueprint.container.BlueprintListener;
 import org.osgi.util.tracker.BundleTracker;
 import org.osgi.util.tracker.BundleTrackerCustomizer;
 import org.osgi.util.tracker.ServiceTracker;
@@ -49,7 +48,7 @@ import org.slf4j.LoggerFactory;
  *
  * @author Thomas Pantelis
  */
-public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCustomizer<Bundle>, EventHandler,
+public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCustomizer<Bundle>, BlueprintListener,
         SynchronousBundleListener {
     private static final Logger LOG = LoggerFactory.getLogger(BlueprintBundleTracker.class);
     private static final String BLUEPRINT_FILE_PATH = "org/opendaylight/blueprint/";
@@ -161,10 +160,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus
     }
 
     private void registerBlueprintEventHandler(final BundleContext context) {
-        Dictionary<String, Object> props = new Hashtable<>();
-        props.put(org.osgi.service.event.EventConstants.EVENT_TOPIC,
-                new String[]{EventConstants.TOPIC_CREATED, EventConstants.TOPIC_FAILURE});
-        eventHandlerReg = context.registerService(EventHandler.class.getName(), this, props);
+        eventHandlerReg = context.registerService(BlueprintListener.class.getName(), this, new Hashtable<>());
     }
 
     /**
@@ -231,15 +227,14 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus
     }
 
     /**
-     * Implemented from EventHandler to listen for blueprint events.
+     * Implemented from BlueprintListener to listen for blueprint events.
      *
      * @param event the event to handle
      */
     @Override
-    public void handleEvent(final Event event) {
-        if (EventConstants.TOPIC_CREATED.equals(event.getTopic())) {
-            LOG.info("Blueprint container for bundle {} was successfully created",
-                    event.getProperty(EventConstants.BUNDLE));
+    public void blueprintEvent(BlueprintEvent event) {
+        if (event.getType() == BlueprintEvent.CREATED) {
+            LOG.info("Blueprint container for bundle {} was successfully created", event.getBundle());
             return;
         }
 
@@ -247,14 +242,13 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus
         // is indicated via a non-null DEPENDENCIES property containing the missing dependencies. The
         // default timeout is 5 min and ideally we would set this to infinite but the timeout can only
         // be set at the bundle level in the manifest - there's no way to set it globally.
-        if (EventConstants.TOPIC_FAILURE.equals(event.getTopic())
-                && event.getProperty(EventConstants.DEPENDENCIES) != null) {
-            Bundle bundle = (Bundle) event.getProperty(EventConstants.BUNDLE);
+        if (event.getType() == BlueprintEvent.FAILURE && event.getDependencies() != null) {
+            Bundle bundle = event.getBundle();
 
             List<Object> paths = findBlueprintPaths(bundle);
             if (!paths.isEmpty()) {
                 LOG.warn("Blueprint container for bundle {} timed out waiting for dependencies - restarting it",
-                        event.getProperty(EventConstants.BUNDLE));
+                        bundle);
 
                 restartService.restartContainer(bundle, paths);
             }