2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.config.yang.messagebus.app.impl;
10 import java.util.HashSet;
13 import org.opendaylight.controller.config.api.DependencyResolver;
14 import org.opendaylight.controller.config.api.ModuleIdentifier;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
17 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
18 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
19 import org.opendaylight.controller.messagebus.app.impl.EventSourceTopology;
20 import org.opendaylight.controller.messagebus.eventsources.netconf.NetconfEventSourceManager;
21 import org.opendaylight.controller.messagebus.spi.EventSource;
22 import org.opendaylight.controller.messagebus.spi.EventSourceRegistration;
23 import org.opendaylight.controller.messagebus.spi.EventSourceRegistry;
24 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
25 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
26 import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
27 import org.osgi.framework.BundleContext;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 import com.google.common.base.Preconditions;
33 public class MessageBusAppImplModule extends org.opendaylight.controller.config.yang.messagebus.app.impl.AbstractMessageBusAppImplModule {
34 private static final Logger LOGGER = LoggerFactory.getLogger(MessageBusAppImplModule.class);
36 private BundleContext bundleContext;
38 public BundleContext getBundleContext() {
42 public void setBundleContext(final BundleContext bundleContext) {
43 this.bundleContext = bundleContext;
46 public MessageBusAppImplModule(final ModuleIdentifier identifier, final DependencyResolver dependencyResolver) {
47 super(identifier, dependencyResolver);
50 public MessageBusAppImplModule(final ModuleIdentifier identifier, final DependencyResolver dependencyResolver,
51 final MessageBusAppImplModule oldModule, final java.lang.AutoCloseable oldInstance) {
52 super(identifier, dependencyResolver, oldModule, oldInstance);
56 protected void customValidation() {
60 public java.lang.AutoCloseable createInstance() {
62 final ProviderContext bindingCtx = getBindingBrokerDependency().registerProvider(new Providers.BindingAware());
63 final ProviderSession domCtx = getDomBrokerDependency().registerProvider(new Providers.BindingIndependent());
64 final DataBroker dataBroker = bindingCtx.getSALService(DataBroker.class);
65 final DOMNotificationPublishService domPublish = domCtx.getService(DOMNotificationPublishService.class);
66 final DOMMountPointService domMount = domCtx.getService(DOMMountPointService.class);
67 final MountPointService bindingMount = bindingCtx.getSALService(MountPointService.class);
68 final RpcProviderRegistry rpcRegistry = bindingCtx.getSALService(RpcProviderRegistry.class);
70 final EventSourceRegistryWrapper eventSourceRegistryWrapper = new EventSourceRegistryWrapper(new EventSourceTopology(dataBroker, rpcRegistry));
71 final NetconfEventSourceManager netconfEventSourceManager = NetconfEventSourceManager.create(dataBroker, domPublish,domMount, bindingMount, eventSourceRegistryWrapper, getNamespaceToStream());
72 eventSourceRegistryWrapper.addAutoCloseable(netconfEventSourceManager);
73 LOGGER.info("Messagebus initialized");
74 return eventSourceRegistryWrapper;
78 //TODO: separate NetconfEventSource into separate bundle, remove this wrapper, return EventSourceTopology directly as EventSourceRegistry
79 private class EventSourceRegistryWrapper implements EventSourceRegistry{
81 private final EventSourceRegistry baseEventSourceRegistry;
82 private final Set<AutoCloseable> autoCloseables = new HashSet<>();
84 public EventSourceRegistryWrapper(EventSourceRegistry baseEventSourceRegistry) {
85 this.baseEventSourceRegistry = baseEventSourceRegistry;
88 public void addAutoCloseable(AutoCloseable ac){
89 Preconditions.checkNotNull(ac);
90 autoCloseables.add(ac);
94 public void close() throws Exception {
95 for(AutoCloseable ac : autoCloseables){
98 baseEventSourceRegistry.close();
102 public <T extends EventSource> EventSourceRegistration<T> registerEventSource(T eventSource) {
103 return this.baseEventSourceRegistry.registerEventSource(eventSource);