X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fmessagebus-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyang%2Fmessagebus%2Fapp%2Fimpl%2FMessageBusAppImplModule.java;h=b870e1453025e3a99b62ec4b7c334964b42984a6;hp=dd68714c963490dcb3064a90335ae891a8a1a9d9;hb=99f994b3e45963f6ef46bc2b71ab4dd8eea8b9ac;hpb=2d62916cb1f4b4045f4fc38fbd313f8339f9ac67 diff --git a/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModule.java b/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModule.java index dd68714c96..b870e14530 100644 --- a/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModule.java +++ b/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModule.java @@ -7,31 +7,19 @@ */ package org.opendaylight.controller.config.yang.messagebus.app.impl; -import java.util.HashSet; -import java.util.Set; - import org.opendaylight.controller.config.api.DependencyResolver; import org.opendaylight.controller.config.api.ModuleIdentifier; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.MountPointService; -import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; -import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService; -import org.opendaylight.controller.messagebus.app.impl.EventSourceTopology; -import org.opendaylight.controller.messagebus.eventsources.netconf.NetconfEventSourceManager; +import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker; import org.opendaylight.controller.messagebus.spi.EventSource; import org.opendaylight.controller.messagebus.spi.EventSourceRegistration; import org.opendaylight.controller.messagebus.spi.EventSourceRegistry; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; -import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; -import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; import org.osgi.framework.BundleContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Preconditions; - -public class MessageBusAppImplModule extends org.opendaylight.controller.config.yang.messagebus.app.impl.AbstractMessageBusAppImplModule { - private static final Logger LOGGER = LoggerFactory.getLogger(MessageBusAppImplModule.class); +@Deprecated +public class MessageBusAppImplModule extends AbstractMessageBusAppImplModule { + private static final Logger LOG = LoggerFactory.getLogger(MessageBusAppImplModule.class); private BundleContext bundleContext; @@ -52,56 +40,24 @@ public class MessageBusAppImplModule extends org.opendaylight.controller.config. super(identifier, dependencyResolver, oldModule, oldInstance); } - @Override - protected void customValidation() { - } - @Override public java.lang.AutoCloseable createInstance() { - - 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 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 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(); } - baseEventSourceRegistry.close(); - } - - @Override - public EventSourceRegistration registerEventSource(T eventSource) { - return this.baseEventSourceRegistry.registerEventSource(eventSource); - } + @Override + public EventSourceRegistration registerEventSource(T eventSource) { + return service.registerEventSource(eventSource); + } + }; } }