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.config.concurrent_data_broker;
10 import com.google.common.collect.Lists;
11 import java.util.EnumMap;
12 import java.util.List;
14 import java.util.concurrent.ExecutorService;
15 import org.opendaylight.controller.cluster.datastore.ConcurrentDOMDataBroker;
16 import org.opendaylight.controller.config.api.DependencyResolver;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
19 import org.opendaylight.controller.md.sal.common.util.jmx.ThreadExecutorStatsMXBeanImpl;
20 import org.opendaylight.controller.md.sal.dom.broker.impl.jmx.CommitStatsMXBeanImpl;
21 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStoreFactory;
22 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
23 import org.opendaylight.yangtools.util.DurationStatisticsTracker;
24 import org.opendaylight.yangtools.util.concurrent.SpecialExecutors;
26 public class DomConcurrentDataBrokerModule extends AbstractDomConcurrentDataBrokerModule {
27 private static final String JMX_BEAN_TYPE = "DOMDataBroker";
29 public DomConcurrentDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final DependencyResolver dependencyResolver) {
30 super(identifier, dependencyResolver);
33 public DomConcurrentDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final DependencyResolver dependencyResolver, final DomConcurrentDataBrokerModule oldModule, final AutoCloseable oldInstance) {
34 super(identifier, dependencyResolver, oldModule, oldInstance);
38 public AutoCloseable createInstance() {
39 //Initializing Operational DOM DataStore defaulting to InMemoryDOMDataStore if one is not configured
40 DOMStore operStore = getOperationalDataStoreDependency();
41 if(operStore == null){
42 //we will default to InMemoryDOMDataStore creation
43 operStore = InMemoryDOMDataStoreFactory.create("DOM-OPER", getSchemaServiceDependency());
46 DOMStore configStore = getConfigDataStoreDependency();
47 if(configStore == null){
48 //we will default to InMemoryDOMDataStore creation
49 configStore = InMemoryDOMDataStoreFactory.create("DOM-CFG", getSchemaServiceDependency());
52 final Map<LogicalDatastoreType, DOMStore> datastores = new EnumMap<>(LogicalDatastoreType.class);
53 datastores.put(LogicalDatastoreType.OPERATIONAL, operStore);
54 datastores.put(LogicalDatastoreType.CONFIGURATION, configStore);
57 * We use an executor for commit ListenableFuture callbacks that favors reusing available
58 * threads over creating new threads at the expense of execution time. The assumption is
59 * that most ListenableFuture callbacks won't execute a lot of business logic where we want
60 * it to run quicker - many callbacks will likely just handle error conditions and do
61 * nothing on success. The executor queue capacity is bounded and, if the capacity is
62 * reached, subsequent submitted tasks will block the caller.
64 ExecutorService listenableFutureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool(
65 getMaxDataBrokerFutureCallbackPoolSize(), getMaxDataBrokerFutureCallbackQueueSize(),
68 final List<AbstractMXBean> mBeans = Lists.newArrayList();
70 final DurationStatisticsTracker commitStatsTracker;
71 final ConcurrentDOMDataBroker cdb = new ConcurrentDOMDataBroker(datastores, listenableFutureExecutor);
72 commitStatsTracker = cdb.getCommitStatsTracker();
74 if(commitStatsTracker != null) {
75 final CommitStatsMXBeanImpl commitStatsMXBean = new CommitStatsMXBeanImpl(
76 commitStatsTracker, JMX_BEAN_TYPE);
77 commitStatsMXBean.registerMBean();
78 mBeans.add(commitStatsMXBean);
81 final AbstractMXBean commitFutureStatsMXBean =
82 ThreadExecutorStatsMXBeanImpl.create(listenableFutureExecutor,
83 "CommitFutureExecutorStats", JMX_BEAN_TYPE, null);
84 if(commitFutureStatsMXBean != null) {
85 mBeans.add(commitFutureStatsMXBean);
88 cdb.setCloseable(new AutoCloseable() {
91 for(AbstractMXBean mBean: mBeans) {
92 mBean.unregisterMBean();