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.datastore;
10 import static com.google.common.base.Verify.verifyNotNull;
12 import com.google.common.annotations.Beta;
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;
36 * OSGi manifestation of a the distributed datastore, as represented by {@link AbstractDataStore}. This component's
37 * configuration is managed by {@link OSGiDistributedDataStore}.
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";
48 private static final Logger LOG = LoggerFactory.getLogger(OSGiDOMStore.class);
50 private LogicalDatastoreType datastoreType;
51 private AbstractDataStore datastore;
54 public ActorUtils getActorUtils() {
55 return datastore.getActorUtils();
59 public <L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerShardConfigListener(
60 final YangInstanceIdentifier internalPath, final DOMDataTreeChangeListener delegate) {
61 return datastore.registerShardConfigListener(internalPath, delegate);
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);
72 public <L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerTreeChangeListener(
73 final YangInstanceIdentifier treeId, final L listener) {
74 return datastore.registerTreeChangeListener(treeId, listener);
78 public <T extends DOMDataTreeCommitCohort> DOMDataTreeCommitCohortRegistration<T> registerCommitCohort(
79 final DOMDataTreeIdentifier path, final T cohort) {
80 return datastore.registerCommitCohort(path, cohort);
84 public DOMStoreTransactionChain createTransactionChain() {
85 return datastore.createTransactionChain();
89 public DOMStoreReadTransaction newReadOnlyTransaction() {
90 return datastore.newReadOnlyTransaction();
94 public DOMStoreWriteTransaction newWriteOnlyTransaction() {
95 return datastore.newWriteOnlyTransaction();
99 public DOMStoreReadWriteTransaction newReadWriteTransaction() {
100 return datastore.newReadWriteTransaction();
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);
113 LOG.info("Datastore service type {} deactivated", datastoreType);