2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.config.yang.md.sal.dom.impl;
10 import com.google.common.collect.ImmutableMap;
11 import com.google.common.util.concurrent.ListeningExecutorService;
12 import com.google.common.util.concurrent.MoreExecutors;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
15 import org.opendaylight.controller.md.sal.dom.broker.impl.DOMDataBrokerImpl;
16 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
18 import org.osgi.framework.BundleContext;
20 import java.util.Hashtable;
21 import java.util.concurrent.Executors;
26 public final class DomInmemoryDataBrokerModule extends
27 org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractDomInmemoryDataBrokerModule {
29 private BundleContext bundleContext;
31 public DomInmemoryDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
32 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
33 super(identifier, dependencyResolver);
36 public DomInmemoryDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
37 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
38 final DomInmemoryDataBrokerModule oldModule, final java.lang.AutoCloseable oldInstance) {
40 super(identifier, dependencyResolver, oldModule, oldInstance);
44 protected void customValidation() {
45 // Add custom validation for module attributes here.
49 public java.lang.AutoCloseable createInstance() {
50 ListeningExecutorService storeExecutor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2));
51 //Initializing Operational DOM DataStore defaulting to InMemoryDOMDataStore if one is not configured
52 DOMStore operStore = getOperationalDataStoreDependency();
53 if(operStore == null){
54 //we will default to InMemoryDOMDataStore creation
55 operStore = new InMemoryDOMDataStore("DOM-OPER", storeExecutor);
56 //here we will register the SchemaContext listener
57 getSchemaServiceDependency().registerSchemaServiceListener((InMemoryDOMDataStore)operStore);
60 DOMStore configStore = getConfigDataStoreDependency();
61 if(configStore == null){
62 //we will default to InMemoryDOMDataStore creation
63 configStore = new InMemoryDOMDataStore("DOM-CFG", storeExecutor);
64 //here we will register the SchemaContext listener
65 getSchemaServiceDependency().registerSchemaServiceListener((InMemoryDOMDataStore)configStore);
67 ImmutableMap<LogicalDatastoreType, DOMStore> datastores = ImmutableMap
68 .<LogicalDatastoreType, DOMStore> builder().put(LogicalDatastoreType.OPERATIONAL, operStore)
69 .put(LogicalDatastoreType.CONFIGURATION, configStore).build();
71 DOMDataBrokerImpl newDataBroker = new DOMDataBrokerImpl(datastores, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()));
73 getBundleContext().registerService(DOMDataBroker.class, newDataBroker, new Hashtable<String, String>());
79 private BundleContext getBundleContext() {
83 void setBundleContext(final BundleContext ctx) {