34d231cf2ab332870ddfd9ca5b6cad6dd37e2d91
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / config / yang / md / sal / dom / impl / DomBrokerImplModule.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.dom.impl;
9
10 import com.google.common.collect.ClassToInstanceMap;
11 import com.google.common.collect.MutableClassToInstanceMap;
12 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
13 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
14 import org.opendaylight.controller.md.sal.dom.broker.impl.compat.BackwardsCompatibleDataBroker;
15 import org.opendaylight.controller.md.sal.dom.broker.impl.mount.DOMMountPointServiceImpl;
16 import org.opendaylight.controller.sal.core.api.BrokerService;
17 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
18 import org.opendaylight.controller.sal.core.api.data.DataBrokerService;
19 import org.opendaylight.controller.sal.core.api.data.DataProviderService;
20 import org.opendaylight.controller.sal.core.api.data.DataStore;
21 import org.opendaylight.controller.sal.core.api.model.SchemaService;
22 import org.opendaylight.controller.sal.core.api.mount.MountProvisionService;
23 import org.opendaylight.controller.sal.core.api.mount.MountService;
24 import org.opendaylight.controller.sal.dom.broker.BackwardsCompatibleMountPointManager;
25 import org.opendaylight.controller.sal.dom.broker.BrokerImpl;
26 import org.opendaylight.controller.sal.dom.broker.DataBrokerImpl;
27 import org.opendaylight.controller.sal.dom.broker.GlobalBundleScanningSchemaServiceImpl;
28 import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareDataStoreAdapter;
29 import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareRpcBroker;
30 import org.opendaylight.controller.sal.dom.broker.impl.SchemaContextProviders;
31 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
32
33 /**
34 *
35 */
36 public final class DomBrokerImplModule extends org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractDomBrokerImplModule
37 {
38
39     public DomBrokerImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
40         super(identifier, dependencyResolver);
41     }
42
43     public DomBrokerImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final DomBrokerImplModule oldModule, final java.lang.AutoCloseable oldInstance) {
44         super(identifier, dependencyResolver, oldModule, oldInstance);
45     }
46
47     @Override
48     public void validate(){
49         super.validate();
50     }
51
52     @Override
53     public java.lang.AutoCloseable createInstance() {
54         final DataStore legacyStore = getDataStoreDependency();
55         final DOMDataBroker asyncBroker= getAsyncDataBrokerDependency();
56
57         ClassToInstanceMap<BrokerService> services = MutableClassToInstanceMap.create();
58
59
60         SchemaService schemaService = getSchemaServiceImpl();
61         services.putInstance(SchemaService.class, schemaService);
62         SchemaAwareRpcBroker router = new SchemaAwareRpcBroker("/", SchemaContextProviders
63                 .fromSchemaService(schemaService));
64         services.putInstance(RpcProvisionRegistry.class, router);
65
66         final DataProviderService legacyData;
67         if(asyncBroker != null) {
68             services.putInstance(DOMDataBroker.class, asyncBroker);
69             legacyData = new BackwardsCompatibleDataBroker(asyncBroker,schemaService);
70         } else {
71             legacyData = createLegacyDataService(legacyStore,schemaService);
72         }
73         services.putInstance(DataProviderService.class,legacyData);
74         services.putInstance(DataBrokerService.class, legacyData);
75
76         final DOMMountPointService mountService = new DOMMountPointServiceImpl();
77         services.putInstance(DOMMountPointService.class, mountService);
78
79         // TODO remove backwards service, use only new DOMMountPointService
80         final MountProvisionService backwardsMountService = new BackwardsCompatibleMountPointManager(mountService);
81         services.putInstance(MountService.class, backwardsMountService);
82         services.putInstance(MountProvisionService.class, backwardsMountService);
83
84         return new BrokerImpl(router, services);
85     }
86
87     private DataProviderService createLegacyDataService(final DataStore legacyStore, final SchemaService schemaService) {
88         InstanceIdentifier rootPath = InstanceIdentifier.builder().toInstance();
89         DataBrokerImpl dataService = new DataBrokerImpl();
90         SchemaAwareDataStoreAdapter wrappedStore = new SchemaAwareDataStoreAdapter();
91         wrappedStore.changeDelegate(legacyStore);
92         wrappedStore.setValidationEnabled(false);
93
94         schemaService.registerSchemaServiceListener(wrappedStore);
95
96         dataService.registerConfigurationReader(rootPath, wrappedStore);
97         dataService.registerCommitHandler(rootPath, wrappedStore);
98         dataService.registerOperationalReader(rootPath, wrappedStore);
99         return dataService;
100     }
101
102     private SchemaService getSchemaServiceImpl() {
103         final SchemaService schemaService;
104         if(getRootSchemaService() != null) {
105             schemaService = getRootSchemaServiceDependency();
106         } else {
107             schemaService = GlobalBundleScanningSchemaServiceImpl.getInstance();
108         }
109         return schemaService;
110     }
111 }

©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.