Merge "Bug:1238 - Revert changes to SshClientAdapter."
[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.Hashtable;
11 import java.util.concurrent.Executors;
12
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;
19
20 import com.google.common.collect.ImmutableMap;
21 import com.google.common.util.concurrent.ListeningExecutorService;
22 import com.google.common.util.concurrent.MoreExecutors;
23
24 /**
25 *
26 */
27 public final class DomInmemoryDataBrokerModule extends
28         org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractDomInmemoryDataBrokerModule {
29
30     private BundleContext bundleContext;
31
32     public DomInmemoryDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
33             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
34         super(identifier, dependencyResolver);
35     }
36
37     public DomInmemoryDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
38             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
39             final DomInmemoryDataBrokerModule oldModule, final java.lang.AutoCloseable oldInstance) {
40
41         super(identifier, dependencyResolver, oldModule, oldInstance);
42     }
43
44     @Override
45     protected void customValidation() {
46         // Add custom validation for module attributes here.
47     }
48
49     @Override
50     public java.lang.AutoCloseable createInstance() {
51         ListeningExecutorService storeExecutor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2));
52         InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("DOM-OPER", storeExecutor);
53         InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("DOM-CFG", storeExecutor);
54         ImmutableMap<LogicalDatastoreType, DOMStore> datastores = ImmutableMap
55                 .<LogicalDatastoreType, DOMStore> builder().put(LogicalDatastoreType.OPERATIONAL, operStore)
56                 .put(LogicalDatastoreType.CONFIGURATION, configStore).build();
57
58         DOMDataBrokerImpl newDataBroker = new DOMDataBrokerImpl(datastores, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()));
59
60         getBundleContext().registerService(DOMDataBroker.class, newDataBroker, new Hashtable<String, String>());
61
62         getSchemaServiceDependency().registerSchemaServiceListener(operStore);
63         getSchemaServiceDependency().registerSchemaServiceListener(configStore);
64
65         return newDataBroker;
66     }
67
68     private BundleContext getBundleContext() {
69         return bundleContext;
70     }
71
72     void setBundleContext(final BundleContext ctx) {
73         bundleContext = ctx;
74     }
75 }