2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.cluster.databroker;
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.ImmutableMap;
12 import java.util.Collection;
13 import java.util.concurrent.ExecutorService;
14 import java.util.concurrent.TimeUnit;
15 import org.opendaylight.controller.md.sal.common.util.jmx.ThreadExecutorStatsMXBeanImpl;
16 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
17 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
18 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
19 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
20 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
21 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
22 import org.opendaylight.mdsal.dom.spi.store.DOMStore;
23 import org.opendaylight.yangtools.util.DurationStatisticsTracker;
24 import org.opendaylight.yangtools.util.concurrent.SpecialExecutors;
25 import org.osgi.service.component.annotations.Activate;
26 import org.osgi.service.component.annotations.Component;
27 import org.osgi.service.component.annotations.Deactivate;
28 import org.osgi.service.component.annotations.Reference;
29 import org.osgi.service.metatype.annotations.AttributeDefinition;
30 import org.osgi.service.metatype.annotations.Designate;
31 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 @Component(immediate = true, configurationPid = "org.opendaylight.controller.cluster.datastore.broker",
37 property = "type=default")
38 @Designate(ocd = OSGiDOMDataBroker.Config.class)
39 public final class OSGiDOMDataBroker implements DOMDataBroker {
40 @ObjectClassDefinition
41 public @interface Config {
42 @AttributeDefinition(name = "max-data-broker-future-callback-queue-size")
43 int callbackQueueSize() default 1000;
44 @AttributeDefinition(name = "max-data-broker-future-callback-pool-size")
45 int callbackPoolSize() default 20;
48 private static final Logger LOG = LoggerFactory.getLogger(OSGiDOMDataBroker.class);
50 @Reference(target = "(type=distributed-config)")
51 DOMStore configDatastore = null;
52 @Reference(target = "(type=distributed-operational)")
53 DOMStore operDatastore = null;
55 private ExecutorService executorService;
56 private ConcurrentDOMDataBroker delegate;
57 private CommitStatsMXBeanImpl commitStats;
58 private ThreadExecutorStatsMXBeanImpl threadStats;
61 public DOMDataTreeReadTransaction newReadOnlyTransaction() {
62 return delegate.newReadOnlyTransaction();
66 public DOMDataTreeWriteTransaction newWriteOnlyTransaction() {
67 return delegate.newWriteOnlyTransaction();
71 public DOMDataTreeReadWriteTransaction newReadWriteTransaction() {
72 return delegate.newReadWriteTransaction();
76 public Collection<Extension> supportedExtensions() {
77 return delegate.supportedExtensions();
81 public DOMTransactionChain createTransactionChain() {
82 return delegate.createTransactionChain();
86 public DOMTransactionChain createMergingTransactionChain() {
87 return delegate.createMergingTransactionChain();
91 void activate(final Config config) {
92 LOG.info("DOM Data Broker starting");
93 final DurationStatisticsTracker commitStatsTracker = DurationStatisticsTracker.createConcurrent();
95 executorService = SpecialExecutors.newBlockingBoundedCachedThreadPool(config.callbackPoolSize(),
96 config.callbackQueueSize(), "CommitFutures", ConcurrentDOMDataBroker.class);
97 delegate = new ConcurrentDOMDataBroker(ImmutableMap.of(
98 LogicalDatastoreType.CONFIGURATION, configDatastore, LogicalDatastoreType.OPERATIONAL, operDatastore),
99 executorService, commitStatsTracker);
101 commitStats = new CommitStatsMXBeanImpl(commitStatsTracker, "DOMDataBroker");
102 commitStats.register();
103 threadStats = ThreadExecutorStatsMXBeanImpl.create(executorService, "CommitFutureExecutorStats",
106 LOG.info("DOM Data Broker started");
111 LOG.info("DOM Data Broker stopping");
112 commitStats.unregister();
113 if (threadStats != null) {
114 threadStats.unregister();
118 executorService.shutdown();
120 executorService.awaitTermination(1, TimeUnit.MINUTES);
121 } catch (InterruptedException e) {
122 LOG.warn("Future executor failed to finish in time, giving up", e);
124 LOG.info("DOM Data Broker stopped");