Bug 488: Removed BundleContext usage for registering to DOM Components.
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / config / yang / md / sal / binding / impl / DataBrokerImplModule.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.md.sal.binding.impl;
9
10 import java.util.concurrent.ExecutorService;
11
12 import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
13 import org.opendaylight.controller.sal.binding.impl.RootDataBrokerImpl;
14 import org.opendaylight.controller.sal.binding.impl.connect.dom.BindingDomConnectorDeployer;
15 import org.opendaylight.controller.sal.binding.impl.connect.dom.BindingIndependentConnector;
16 import org.opendaylight.controller.sal.binding.impl.forward.DomForwardedDataBrokerImpl;
17 import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
18 import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService;
19
20 /**
21 *
22 */
23 public final class DataBrokerImplModule extends
24         org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractDataBrokerImplModule {
25
26     public DataBrokerImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
27             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
28         super(identifier, dependencyResolver);
29     }
30
31     public DataBrokerImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
32             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
33             final DataBrokerImplModule oldModule, final java.lang.AutoCloseable oldInstance) {
34         super(identifier, dependencyResolver, oldModule, oldInstance);
35     }
36
37     @Override
38     public void validate() {
39         super.validate();
40     }
41
42     @Override
43     public java.lang.AutoCloseable createInstance() {
44         RootDataBrokerImpl dataBindingBroker;
45
46
47         ExecutorService listeningExecutor = SingletonHolder.getDefaultCommitExecutor();
48         BindingIndependentMappingService potentialMapping = getMappingServiceDependency();
49         if (getDomBrokerDependency() != null && potentialMapping != null) {
50
51             dataBindingBroker = createDomConnectedBroker(listeningExecutor,potentialMapping);
52         } else {
53             dataBindingBroker = createStandAloneBroker(listeningExecutor);
54         }
55         dataBindingBroker.registerRuntimeBean(getRootRuntimeBeanRegistratorWrapper());
56         dataBindingBroker.setNotificationExecutor(SingletonHolder.getDefaultChangeEventExecutor());
57         return dataBindingBroker;
58     }
59
60
61     private RootDataBrokerImpl createStandAloneBroker(final ExecutorService listeningExecutor) {
62         RootDataBrokerImpl broker = new RootDataBrokerImpl();
63         broker.setExecutor(listeningExecutor);
64         return broker;
65     }
66
67     private RootDataBrokerImpl createDomConnectedBroker(final ExecutorService listeningExecutor, final BindingIndependentMappingService mappingService) {
68         DomForwardedDataBrokerImpl forwardedBroker = new DomForwardedDataBrokerImpl();
69         forwardedBroker.setExecutor(listeningExecutor);
70         BindingIndependentConnector connector = BindingDomConnectorDeployer.createConnector(mappingService);
71         getDomBrokerDependency().registerProvider(forwardedBroker, null);
72         ProviderSession domContext = forwardedBroker.getDomProviderContext();
73         forwardedBroker.setConnector(connector);
74         forwardedBroker.setDomProviderContext(domContext);
75         forwardedBroker.startForwarding();
76         return forwardedBroker;
77     }
78
79 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.