Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / OSGiDOMStore.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.cluster.datastore;
9
10 import static com.google.common.base.Verify.verifyNotNull;
11
12 import com.google.common.annotations.Beta;
13 import java.util.Map;
14 import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
15 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
16 import org.opendaylight.mdsal.dom.api.DOMDataBroker.CommitCohortExtension;
17 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
18 import org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohort;
19 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
20 import org.opendaylight.mdsal.dom.spi.store.DOMStore;
21 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
22 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
23 import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain;
24 import org.opendaylight.mdsal.dom.spi.store.DOMStoreTreeChangePublisher;
25 import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
26 import org.opendaylight.yangtools.concepts.Registration;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
28 import org.osgi.service.component.annotations.Activate;
29 import org.osgi.service.component.annotations.Component;
30 import org.osgi.service.component.annotations.Deactivate;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 /**
35  * OSGi manifestation of a the distributed datastore, as represented by {@link AbstractDataStore}. This component's
36  * configuration is managed by {@link OSGiDistributedDataStore}.
37  */
38 @Beta
39 @Component(factory = OSGiDOMStore.FACTORY_NAME, service = { DOMStore.class,  DistributedDataStoreInterface.class })
40 public final class OSGiDOMStore
41         implements DistributedDataStoreInterface, DOMStoreTreeChangePublisher, CommitCohortExtension {
42     // OSGi DS Component Factory name
43     static final String FACTORY_NAME = "org.opendaylight.controller.cluster.datastore.OSGiDOMStore";
44     static final String DATASTORE_INST_PROP = ".datastore.instance";
45     static final String DATASTORE_TYPE_PROP = ".datastore.type";
46
47     private static final Logger LOG = LoggerFactory.getLogger(OSGiDOMStore.class);
48
49     private final LogicalDatastoreType datastoreType;
50     private AbstractDataStore datastore;
51
52     @Activate
53     public OSGiDOMStore(final Map<String, ?> properties) {
54         datastoreType = (LogicalDatastoreType) verifyNotNull(properties.get(DATASTORE_TYPE_PROP));
55         datastore = (AbstractDataStore) verifyNotNull(properties.get(DATASTORE_INST_PROP));
56         LOG.info("Datastore service type {} activated", datastoreType);
57     }
58
59     @Deactivate
60     void deactivate() {
61         datastore = null;
62         LOG.info("Datastore service type {} deactivated", datastoreType);
63     }
64
65     @Override
66     public ActorUtils getActorUtils() {
67         return datastore.getActorUtils();
68     }
69
70     @Override
71     public Registration registerProxyListener(final YangInstanceIdentifier shardLookup,
72             final YangInstanceIdentifier insideShard, final DOMDataTreeChangeListener delegate) {
73         return datastore.registerProxyListener(shardLookup, insideShard, delegate);
74     }
75
76     @Override
77     public Registration registerTreeChangeListener(final YangInstanceIdentifier treeId,
78             final DOMDataTreeChangeListener listener) {
79         return datastore.registerTreeChangeListener(treeId, listener);
80     }
81
82     @Override
83     public Registration registerCommitCohort(final DOMDataTreeIdentifier path, final DOMDataTreeCommitCohort cohort) {
84         return datastore.registerCommitCohort(path, cohort);
85     }
86
87     @Override
88     public DOMStoreTransactionChain createTransactionChain() {
89         return datastore.createTransactionChain();
90     }
91
92     @Override
93     public DOMStoreReadTransaction newReadOnlyTransaction() {
94         return datastore.newReadOnlyTransaction();
95     }
96
97     @Override
98     public DOMStoreWriteTransaction newWriteOnlyTransaction() {
99         return datastore.newWriteOnlyTransaction();
100     }
101
102     @Override
103     public DOMStoreReadWriteTransaction newReadWriteTransaction() {
104         return datastore.newReadWriteTransaction();
105     }
106
107     @Override
108     public Registration registerLegacyTreeChangeListener(final YangInstanceIdentifier treeId,
109             final DOMDataTreeChangeListener listener) {
110         return datastore.registerLegacyTreeChangeListener(treeId, listener);
111     }
112 }