Fix followerDistributedDataStore tear down
[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.DOMDataTreeChangeListener;
17 import org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohort;
18 import org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohortRegistration;
19 import org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohortRegistry;
20 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
21 import org.opendaylight.mdsal.dom.spi.store.DOMStore;
22 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
23 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
24 import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain;
25 import org.opendaylight.mdsal.dom.spi.store.DOMStoreTreeChangePublisher;
26 import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
27 import org.opendaylight.yangtools.concepts.ListenerRegistration;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
29 import org.osgi.service.component.annotations.Activate;
30 import org.osgi.service.component.annotations.Component;
31 import org.osgi.service.component.annotations.Deactivate;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 /**
36  * OSGi manifestation of a the distributed datastore, as represented by {@link AbstractDataStore}. This component's
37  * configuration is managed by {@link OSGiDistributedDataStore}.
38  */
39 @Beta
40 @Component(factory = OSGiDOMStore.FACTORY_NAME, service = { DOMStore.class,  DistributedDataStoreInterface.class })
41 public final class OSGiDOMStore
42         implements DistributedDataStoreInterface, DOMStoreTreeChangePublisher, DOMDataTreeCommitCohortRegistry {
43     // OSGi DS Component Factory name
44     static final String FACTORY_NAME = "org.opendaylight.controller.cluster.datastore.OSGiDOMStore";
45     static final String DATASTORE_INST_PROP = ".datastore.instance";
46     static final String DATASTORE_TYPE_PROP = ".datastore.type";
47
48     private static final Logger LOG = LoggerFactory.getLogger(OSGiDOMStore.class);
49
50     private LogicalDatastoreType datastoreType;
51     private AbstractDataStore datastore;
52
53     @Override
54     public ActorUtils getActorUtils() {
55         return datastore.getActorUtils();
56     }
57
58     @Override
59     public <L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerShardConfigListener(
60             final YangInstanceIdentifier internalPath, final DOMDataTreeChangeListener delegate) {
61         return datastore.registerShardConfigListener(internalPath, delegate);
62     }
63
64     @Override
65     public <L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerProxyListener(
66             final YangInstanceIdentifier shardLookup, final YangInstanceIdentifier insideShard,
67             final DOMDataTreeChangeListener delegate) {
68         return datastore.registerProxyListener(shardLookup, insideShard, delegate);
69     }
70
71     @Override
72     public <L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerTreeChangeListener(
73             final YangInstanceIdentifier treeId, final L listener) {
74         return datastore.registerTreeChangeListener(treeId, listener);
75     }
76
77     @Override
78     public <T extends DOMDataTreeCommitCohort> DOMDataTreeCommitCohortRegistration<T> registerCommitCohort(
79             final DOMDataTreeIdentifier path, final T cohort) {
80         return datastore.registerCommitCohort(path, cohort);
81     }
82
83     @Override
84     public DOMStoreTransactionChain createTransactionChain() {
85         return datastore.createTransactionChain();
86     }
87
88     @Override
89     public DOMStoreReadTransaction newReadOnlyTransaction() {
90         return datastore.newReadOnlyTransaction();
91     }
92
93     @Override
94     public DOMStoreWriteTransaction newWriteOnlyTransaction() {
95         return datastore.newWriteOnlyTransaction();
96     }
97
98     @Override
99     public DOMStoreReadWriteTransaction newReadWriteTransaction() {
100         return datastore.newReadWriteTransaction();
101     }
102
103     @Activate
104     void activate(final Map<String, ?> properties) {
105         datastoreType = (LogicalDatastoreType) verifyNotNull(properties.get(DATASTORE_TYPE_PROP));
106         datastore = (AbstractDataStore) verifyNotNull(properties.get(DATASTORE_INST_PROP));
107         LOG.info("Datastore service type {} activated", datastoreType);
108     }
109
110     @Deactivate
111     void deactivate() {
112         datastore = null;
113         LOG.info("Datastore service type {} deactivated", datastoreType);
114     }
115 }