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;
*
* @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/";
}
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<>());
}
/**
}
/**
- * 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;
}
// 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);
}