Fix modules Restconf call for mounted devices
[controller.git] / opendaylight / md-sal / messagebus-impl / src / main / java / org / opendaylight / controller / config / yang / messagebus / app / impl / MessageBusAppImplModule.java
1 /**
2  * Copyright (c) 2014 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 org.opendaylight.controller.config.api.DependencyResolver;
11 import org.opendaylight.controller.config.api.ModuleIdentifier;
12 import org.opendaylight.controller.mdsal.InitializationContext;
13 import org.opendaylight.controller.mdsal.Providers;
14 import org.osgi.framework.BundleContext;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 import java.util.List;
19
20 public class MessageBusAppImplModule extends org.opendaylight.controller.config.yang.messagebus.app.impl.AbstractMessageBusAppImplModule {
21     private static final Logger LOGGER = LoggerFactory.getLogger(MessageBusAppImplModule.class);
22
23     private BundleContext bundleContext;
24
25     public BundleContext getBundleContext() {
26         return bundleContext;
27     }
28
29     public void setBundleContext(BundleContext bundleContext) {
30         this.bundleContext = bundleContext;
31     }
32
33     public MessageBusAppImplModule( ModuleIdentifier identifier, DependencyResolver dependencyResolver) {
34         super(identifier, dependencyResolver);
35     }
36
37     public MessageBusAppImplModule( ModuleIdentifier identifier,
38                                     DependencyResolver dependencyResolver,
39                                     MessageBusAppImplModule oldModule,
40                                     java.lang.AutoCloseable oldInstance) {
41         super(identifier, dependencyResolver, oldModule, oldInstance);
42     }
43
44     @Override
45     protected void customValidation() {}
46
47     @Override
48     public java.lang.AutoCloseable createInstance() {
49         List<NamespaceToStream> namespaceMapping = getNamespaceToStream();
50         InitializationContext ic = new InitializationContext(namespaceMapping);
51
52         final Providers.BindingAware bap = new Providers.BindingAware(ic);
53         final Providers.BindingIndependent bip = new Providers.BindingIndependent(ic);
54
55         getBindingBrokerDependency().registerProvider(bap, getBundleContext());
56         getDomBrokerDependency().registerProvider(bip);
57
58         AutoCloseable closer = new AutoCloseable() {
59             @Override public void close()  {
60                 closeProvider(bap);
61                 closeProvider(bip);
62             }
63         };
64
65         return closer;
66     }
67
68     private void closeProvider(AutoCloseable closable) {
69         try {
70             closable.close();
71         } catch (Exception e) {
72             LOGGER.error("Exception while closing: {}\n Exception: {}", closable, e);
73         }
74     }
75 }