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 java.util.concurrent.Executors;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitDeadlockException;
14 import org.opendaylight.controller.md.sal.dom.broker.impl.DOMDataBrokerImpl;
15 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
16 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
17 import org.opendaylight.yangtools.util.concurrent.DeadlockDetectingListeningExecutorService;
19 import com.google.common.collect.ImmutableMap;
20 import com.google.common.util.concurrent.ListeningExecutorService;
21 import com.google.common.util.concurrent.MoreExecutors;
26 public final class DomInmemoryDataBrokerModule extends
27 org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractDomInmemoryDataBrokerModule {
29 public DomInmemoryDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
30 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
31 super(identifier, dependencyResolver);
34 public DomInmemoryDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
35 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
36 final DomInmemoryDataBrokerModule oldModule, final java.lang.AutoCloseable oldInstance) {
38 super(identifier, dependencyResolver, oldModule, oldInstance);
42 protected void customValidation() {
43 // Add custom validation for module attributes here.
47 public java.lang.AutoCloseable createInstance() {
48 ListeningExecutorService storeExecutor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2));
49 //Initializing Operational DOM DataStore defaulting to InMemoryDOMDataStore if one is not configured
50 DOMStore operStore = getOperationalDataStoreDependency();
51 if(operStore == null){
52 //we will default to InMemoryDOMDataStore creation
53 operStore = new InMemoryDOMDataStore("DOM-OPER", storeExecutor);
54 //here we will register the SchemaContext listener
55 getSchemaServiceDependency().registerSchemaContextListener((InMemoryDOMDataStore)operStore);
58 DOMStore configStore = getConfigDataStoreDependency();
59 if(configStore == null){
60 //we will default to InMemoryDOMDataStore creation
61 configStore = new InMemoryDOMDataStore("DOM-CFG", storeExecutor);
62 //here we will register the SchemaContext listener
63 getSchemaServiceDependency().registerSchemaContextListener((InMemoryDOMDataStore)configStore);
65 ImmutableMap<LogicalDatastoreType, DOMStore> datastores = ImmutableMap
66 .<LogicalDatastoreType, DOMStore> builder().put(LogicalDatastoreType.OPERATIONAL, operStore)
67 .put(LogicalDatastoreType.CONFIGURATION, configStore).build();
69 DOMDataBrokerImpl newDataBroker = new DOMDataBrokerImpl(datastores,
70 new DeadlockDetectingListeningExecutorService(Executors.newSingleThreadExecutor(),
71 TransactionCommitDeadlockException.DEADLOCK_EXECUTOR_FUNCTION));