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.List;
11 import org.opendaylight.controller.config.api.DependencyResolver;
12 import org.opendaylight.controller.config.api.ModuleIdentifier;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
15 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
16 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
17 import org.opendaylight.controller.messagebus.app.impl.EventSourceTopology;
18 import org.opendaylight.controller.messagebus.app.impl.NetconfEventSourceManager;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
20 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
21 import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
22 import org.osgi.framework.BundleContext;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class MessageBusAppImplModule extends
27 org.opendaylight.controller.config.yang.messagebus.app.impl.AbstractMessageBusAppImplModule {
28 private static final Logger LOGGER = LoggerFactory.getLogger(MessageBusAppImplModule.class);
30 private BundleContext bundleContext;
32 public BundleContext getBundleContext() {
36 public void setBundleContext(final BundleContext bundleContext) {
37 this.bundleContext = bundleContext;
40 public MessageBusAppImplModule(final ModuleIdentifier identifier, final DependencyResolver dependencyResolver) {
41 super(identifier, dependencyResolver);
44 public MessageBusAppImplModule(final ModuleIdentifier identifier, final DependencyResolver dependencyResolver,
45 final MessageBusAppImplModule oldModule, final java.lang.AutoCloseable oldInstance) {
46 super(identifier, dependencyResolver, oldModule, oldInstance);
50 protected void customValidation() {
54 public java.lang.AutoCloseable createInstance() {
55 final List<NamespaceToStream> namespaceMapping = getNamespaceToStream();
57 final ProviderContext bindingCtx = getBindingBrokerDependency().registerProvider(new Providers.BindingAware());
58 final ProviderSession domCtx = getDomBrokerDependency().registerProvider(new Providers.BindingIndependent());
60 final DataBroker dataBroker = bindingCtx.getSALService(DataBroker.class);
61 final DOMNotificationPublishService domPublish = domCtx.getService(DOMNotificationPublishService.class);
62 final DOMMountPointService domMount = domCtx.getService(DOMMountPointService.class);
63 final MountPointService bindingMount = bindingCtx.getSALService(MountPointService.class);
64 final RpcProviderRegistry rpcRegistry = bindingCtx.getSALService(RpcProviderRegistry.class);
66 final EventSourceTopology eventSourceTopology = new EventSourceTopology(dataBroker, rpcRegistry);
67 final NetconfEventSourceManager eventSourceManager = new NetconfEventSourceManager(dataBroker, domPublish,
68 domMount, bindingMount, eventSourceTopology, getNamespaceToStream());
70 final AutoCloseable closer = new AutoCloseable() {
73 eventSourceTopology.close();
74 eventSourceManager.close();
81 private void closeProvider(final AutoCloseable closable) {
84 } catch (final Exception e) {
85 LOGGER.error("Exception while closing: {}\n Exception: {}", closable, e);