-
- final ProviderContext bindingCtx = getBindingBrokerDependency().registerProvider(new Providers.BindingAware());
- final ProviderSession domCtx = getDomBrokerDependency().registerProvider(new Providers.BindingIndependent());
- final DataBroker dataBroker = bindingCtx.getSALService(DataBroker.class);
- final DOMNotificationPublishService domPublish = domCtx.getService(DOMNotificationPublishService.class);
- final DOMMountPointService domMount = domCtx.getService(DOMMountPointService.class);
- final MountPointService bindingMount = bindingCtx.getSALService(MountPointService.class);
- final RpcProviderRegistry rpcRegistry = bindingCtx.getSALService(RpcProviderRegistry.class);
-
- final EventSourceRegistryWrapper eventSourceRegistryWrapper = new EventSourceRegistryWrapper(new EventSourceTopology(dataBroker, rpcRegistry));
- final NetconfEventSourceManager netconfEventSourceManager = NetconfEventSourceManager.create(dataBroker, domPublish,domMount, bindingMount, eventSourceRegistryWrapper, getNamespaceToStream());
- eventSourceRegistryWrapper.addAutoCloseable(netconfEventSourceManager);
- LOGGER.info("Messagebus initialized");
- return eventSourceRegistryWrapper;
-
- }
-
- //TODO: separate NetconfEventSource into separate bundle, remove this wrapper, return EventSourceTopology directly as EventSourceRegistry
- private class EventSourceRegistryWrapper implements EventSourceRegistry{
-
- private final EventSourceRegistry baseEventSourceRegistry;
- private final Set<AutoCloseable> autoCloseables = new HashSet<>();
-
- public EventSourceRegistryWrapper(EventSourceRegistry baseEventSourceRegistry) {
- this.baseEventSourceRegistry = baseEventSourceRegistry;
- }
-
- public void addAutoCloseable(AutoCloseable ac){
- Preconditions.checkNotNull(ac);
- autoCloseables.add(ac);
- }
-
- @Override
- public void close() throws Exception {
- for(AutoCloseable ac : autoCloseables){
- ac.close();
+ final WaitingServiceTracker<EventSourceRegistry> tracker =
+ WaitingServiceTracker.create(EventSourceRegistry.class, bundleContext);
+ final EventSourceRegistry service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
+
+ return new EventSourceRegistry() {
+ @Override
+ public void close() {
+ // We need to close the WaitingServiceTracker however we don't want to close the actual
+ // service instance because its life-cycle is controlled via blueprint.
+ tracker.close();