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.Executor;
11 import java.util.concurrent.ExecutorService;
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.InMemoryDOMDataStoreFactory;
16 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
17 import org.opendaylight.yangtools.util.concurrent.DeadlockDetectingListeningExecutorService;
18 import org.opendaylight.yangtools.util.concurrent.SpecialExecutors;
19 import com.google.common.collect.ImmutableMap;
24 public final class DomInmemoryDataBrokerModule extends
25 org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractDomInmemoryDataBrokerModule {
27 public DomInmemoryDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
28 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
29 super(identifier, dependencyResolver);
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) {
36 super(identifier, dependencyResolver, oldModule, oldInstance);
40 protected void customValidation() {
41 // Add custom validation for module attributes here.
45 public java.lang.AutoCloseable createInstance() {
46 //Initializing Operational DOM DataStore defaulting to InMemoryDOMDataStore if one is not configured
47 DOMStore operStore = getOperationalDataStoreDependency();
48 if(operStore == null){
49 //we will default to InMemoryDOMDataStore creation
50 operStore = InMemoryDOMDataStoreFactory.create("DOM-OPER", getSchemaServiceDependency());
53 DOMStore configStore = getConfigDataStoreDependency();
54 if(configStore == null){
55 //we will default to InMemoryDOMDataStore creation
56 configStore = InMemoryDOMDataStoreFactory.create("DOM-CFG", getSchemaServiceDependency());
58 ImmutableMap<LogicalDatastoreType, DOMStore> datastores = ImmutableMap
59 .<LogicalDatastoreType, DOMStore> builder().put(LogicalDatastoreType.OPERATIONAL, operStore)
60 .put(LogicalDatastoreType.CONFIGURATION, configStore).build();
63 * We use a single-threaded executor for commits with a bounded queue capacity. If the
64 * queue capacity is reached, subsequent commit tasks will be rejected and the commits will
65 * fail. This is done to relieve back pressure. This should be an extreme scenario - either
66 * there's deadlock(s) somewhere and the controller is unstable or some rogue component is
67 * continuously hammering commits too fast or the controller is just over-capacity for the
68 * system it's running on.
70 ExecutorService commitExecutor = SpecialExecutors.newBoundedSingleThreadExecutor(
71 getMaxDataBrokerCommitQueueSize(), "WriteTxCommit");
74 * We use an executor for commit ListenableFuture callbacks that favors reusing available
75 * threads over creating new threads at the expense of execution time. The assumption is
76 * that most ListenableFuture callbacks won't execute a lot of business logic where we want
77 * it to run quicker - many callbacks will likely just handle error conditions and do
78 * nothing on success. The executor queue capacity is bounded and, if the capacity is
79 * reached, subsequent submitted tasks will block the caller.
81 Executor listenableFutureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool(
82 getMaxDataBrokerFutureCallbackPoolSize(), getMaxDataBrokerFutureCallbackQueueSize(),
85 DOMDataBrokerImpl newDataBroker = new DOMDataBrokerImpl(datastores,
86 new DeadlockDetectingListeningExecutorService(commitExecutor,
87 TransactionCommitDeadlockException.DEADLOCK_EXECUTOR_FUNCTION,
88 listenableFutureExecutor));