Bug 488: Removed BundleContext from InMemoryDataBroker.
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / config / yang / md / sal / dom / impl / DomInmemoryDataBrokerModule.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 java.util.concurrent.Executors;
11
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.controller.md.sal.dom.broker.impl.DOMDataBrokerImpl;
14 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
15 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
16
17 import com.google.common.collect.ImmutableMap;
18 import com.google.common.util.concurrent.ListeningExecutorService;
19 import com.google.common.util.concurrent.MoreExecutors;
20
21 /**
22 *
23 */
24 public final class DomInmemoryDataBrokerModule extends
25         org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractDomInmemoryDataBrokerModule {
26
27     public DomInmemoryDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
28             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
29         super(identifier, dependencyResolver);
30     }
31
32     public DomInmemoryDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
33             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
34             final DomInmemoryDataBrokerModule oldModule, final java.lang.AutoCloseable oldInstance) {
35
36         super(identifier, dependencyResolver, oldModule, oldInstance);
37     }
38
39     @Override
40     protected void customValidation() {
41         // Add custom validation for module attributes here.
42     }
43
44     @Override
45     public java.lang.AutoCloseable createInstance() {
46         ListeningExecutorService storeExecutor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2));
47         //Initializing Operational DOM DataStore defaulting to InMemoryDOMDataStore if one is not configured
48         DOMStore operStore =  getOperationalDataStoreDependency();
49         if(operStore == null){
50            //we will default to InMemoryDOMDataStore creation
51           operStore = new InMemoryDOMDataStore("DOM-OPER", storeExecutor);
52           //here we will register the SchemaContext listener
53           getSchemaServiceDependency().registerSchemaServiceListener((InMemoryDOMDataStore)operStore);
54         }
55
56         DOMStore configStore = getConfigDataStoreDependency();
57         if(configStore == null){
58            //we will default to InMemoryDOMDataStore creation
59            configStore = new InMemoryDOMDataStore("DOM-CFG", storeExecutor);
60           //here we will register the SchemaContext listener
61           getSchemaServiceDependency().registerSchemaServiceListener((InMemoryDOMDataStore)configStore);
62         }
63         ImmutableMap<LogicalDatastoreType, DOMStore> datastores = ImmutableMap
64                 .<LogicalDatastoreType, DOMStore> builder().put(LogicalDatastoreType.OPERATIONAL, operStore)
65                 .put(LogicalDatastoreType.CONFIGURATION, configStore).build();
66
67         DOMDataBrokerImpl newDataBroker = new DOMDataBrokerImpl(datastores, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()));
68
69         return newDataBroker;
70     }
71 }

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