Merge "BUG 2854 : Do not add empty read write transactions to the replicable journal"
[controller.git] / opendaylight / md-sal / messagebus-impl / src / main / java / org / opendaylight / controller / config / yang / messagebus / app / impl / MessageBusAppImplModule.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.config.yang.messagebus.app.impl;
9
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;
25
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);
29
30     private BundleContext bundleContext;
31
32     public BundleContext getBundleContext() {
33         return bundleContext;
34     }
35
36     public void setBundleContext(final BundleContext bundleContext) {
37         this.bundleContext = bundleContext;
38     }
39
40     public MessageBusAppImplModule(final ModuleIdentifier identifier, final DependencyResolver dependencyResolver) {
41         super(identifier, dependencyResolver);
42     }
43
44     public MessageBusAppImplModule(final ModuleIdentifier identifier, final DependencyResolver dependencyResolver,
45             final MessageBusAppImplModule oldModule, final java.lang.AutoCloseable oldInstance) {
46         super(identifier, dependencyResolver, oldModule, oldInstance);
47     }
48
49     @Override
50     protected void customValidation() {
51     }
52
53     @Override
54     public java.lang.AutoCloseable createInstance() {
55         final List<NamespaceToStream> namespaceMapping = getNamespaceToStream();
56
57         final ProviderContext bindingCtx = getBindingBrokerDependency().registerProvider(new Providers.BindingAware());
58         final ProviderSession domCtx = getDomBrokerDependency().registerProvider(new Providers.BindingIndependent());
59
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);
65
66         final EventSourceTopology eventSourceTopology = new EventSourceTopology(dataBroker, rpcRegistry);
67         final NetconfEventSourceManager eventSourceManager = new NetconfEventSourceManager(dataBroker, domPublish,
68                 domMount, bindingMount, eventSourceTopology, getNamespaceToStream());
69
70         final AutoCloseable closer = new AutoCloseable() {
71             @Override
72             public void close() {
73                 eventSourceTopology.close();
74                 eventSourceManager.close();
75             }
76         };
77
78         return closer;
79     }
80
81     private void closeProvider(final AutoCloseable closable) {
82         try {
83             closable.close();
84         } catch (final Exception e) {
85             LOGGER.error("Exception while closing: {}\n Exception: {}", closable, e);
86         }
87     }
88 }