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 boolean canReuseInstance(AbstractDomConcurrentDataBrokerModule oldModule) {
43 public AutoCloseable createInstance() {
44 //Initializing Operational DOM DataStore defaulting to InMemoryDOMDataStore if one is not configured
45 DOMStore operStore = getOperationalDataStoreDependency();
46 if(operStore == null){
47 //we will default to InMemoryDOMDataStore creation
48 operStore = InMemoryDOMDataStoreFactory.create("DOM-OPER", getSchemaServiceDependency());
51 DOMStore configStore = getConfigDataStoreDependency();
52 if(configStore == null){
53 //we will default to InMemoryDOMDataStore creation
54 configStore = InMemoryDOMDataStoreFactory.create("DOM-CFG", getSchemaServiceDependency());
57 final Map<LogicalDatastoreType, DOMStore> datastores = new EnumMap<>(LogicalDatastoreType.class);
58 datastores.put(LogicalDatastoreType.OPERATIONAL, operStore);
59 datastores.put(LogicalDatastoreType.CONFIGURATION, configStore);
62 * We use an executor for commit ListenableFuture callbacks that favors reusing available
63 * threads over creating new threads at the expense of execution time. The assumption is
64 * that most ListenableFuture callbacks won't execute a lot of business logic where we want
65 * it to run quicker - many callbacks will likely just handle error conditions and do
66 * nothing on success. The executor queue capacity is bounded and, if the capacity is
67 * reached, subsequent submitted tasks will block the caller.
69 ExecutorService listenableFutureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool(
70 getMaxDataBrokerFutureCallbackPoolSize(), getMaxDataBrokerFutureCallbackQueueSize(),
73 final List<AbstractMXBean> mBeans = Lists.newArrayList();
75 final DurationStatisticsTracker commitStatsTracker;
76 final ConcurrentDOMDataBroker cdb = new ConcurrentDOMDataBroker(datastores, listenableFutureExecutor);
77 commitStatsTracker = cdb.getCommitStatsTracker();
79 if(commitStatsTracker != null) {
80 final CommitStatsMXBeanImpl commitStatsMXBean = new CommitStatsMXBeanImpl(
81 commitStatsTracker, JMX_BEAN_TYPE);
82 commitStatsMXBean.registerMBean();
83 mBeans.add(commitStatsMXBean);
86 final AbstractMXBean commitFutureStatsMXBean =
87 ThreadExecutorStatsMXBeanImpl.create(listenableFutureExecutor,
88 "CommitFutureExecutorStats", JMX_BEAN_TYPE, null);
89 if(commitFutureStatsMXBean != null) {
90 mBeans.add(commitFutureStatsMXBean);
93 cdb.setCloseable(new AutoCloseable() {
96 for(AbstractMXBean mBean: mBeans) {
97 mBean.unregisterMBean();