X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShardDataTree.java;h=ad5aab345395c0d655a48c3fd59aeeab68db9669;hb=7161b121b21aeea325fe33485c841af31f9f0cfd;hp=18f0cddf179b2ed010123c6eaf9f65f320314049;hpb=d9ea4400df226eb65c964ab0cb2aa81ee495ba15;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java index 18f0cddf17..ad5aab3453 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java @@ -19,16 +19,17 @@ import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataCh import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener; import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener; import org.opendaylight.controller.md.sal.dom.store.impl.DataChangeListenerRegistration; -import org.opendaylight.controller.md.sal.dom.store.impl.ResolveDataChangeEventsTask; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.ListenerTree; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree; +import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.slf4j.Logger; @@ -45,17 +46,27 @@ import org.slf4j.LoggerFactory; public class ShardDataTree extends ShardDataTreeTransactionParent { private static final Logger LOG = LoggerFactory.getLogger(ShardDataTree.class); private static final YangInstanceIdentifier ROOT_PATH = YangInstanceIdentifier.builder().build(); - private static final ShardDataTreeNotificationManager MANAGER = new ShardDataTreeNotificationManager(); + private final Map transactionChains = new HashMap<>(); - private final ShardDataTreeChangePublisher treeChangePublisher = new ShardDataTreeChangePublisher(); - private final ListenerTree listenerTree = ListenerTree.create(); + private final ShardDataTreeChangeListenerPublisher treeChangeListenerPublisher; + private final ShardDataChangeListenerPublisher dataChangeListenerPublisher; private final TipProducingDataTree dataTree; + private final String logContext; private SchemaContext schemaContext; - public ShardDataTree(final SchemaContext schemaContext) { - dataTree = InMemoryDataTreeFactory.getInstance().create(); + public ShardDataTree(final SchemaContext schemaContext, final TreeType treeType, + final ShardDataTreeChangeListenerPublisher treeChangeListenerPublisher, + final ShardDataChangeListenerPublisher dataChangeListenerPublisher, final String logContext) { + dataTree = InMemoryDataTreeFactory.getInstance().create(treeType); updateSchemaContext(schemaContext); + this.treeChangeListenerPublisher = treeChangeListenerPublisher; + this.dataChangeListenerPublisher = dataChangeListenerPublisher; + this.logContext = logContext; + } + public ShardDataTree(final SchemaContext schemaContext, final TreeType treeType) { + this(schemaContext, treeType, new DefaultShardDataTreeChangeListenerPublisher(), + new DefaultShardDataChangeListenerPublisher(), ""); } public TipProducingDataTree getDataTree() { @@ -100,33 +111,27 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { } public void notifyListeners(final DataTreeCandidate candidate) { - LOG.debug("Notifying listeners on candidate {}", candidate); - - // DataTreeChanges first, as they are more light-weight - treeChangePublisher.publishChanges(candidate); - - // DataChanges second, as they are heavier - ResolveDataChangeEventsTask.create(candidate, listenerTree).resolve(MANAGER); + treeChangeListenerPublisher.publishChanges(candidate, logContext); + dataChangeListenerPublisher.publishChanges(candidate, logContext); } void notifyOfInitialData(DataChangeListenerRegistration>> listenerReg, Optional currentState) { if(currentState.isPresent()) { - ListenerTree localListenerTree = ListenerTree.create(); - localListenerTree.registerDataChangeListener(listenerReg.getPath(), listenerReg.getInstance(), + ShardDataChangeListenerPublisher localPublisher = dataChangeListenerPublisher.newInstance(); + localPublisher.registerDataChangeListener(listenerReg.getPath(), listenerReg.getInstance(), listenerReg.getScope()); - - ResolveDataChangeEventsTask.create(currentState.get(), localListenerTree).resolve(MANAGER); + localPublisher.publishChanges(currentState.get(), logContext); } } void notifyOfInitialData(final YangInstanceIdentifier path, final DOMDataTreeChangeListener listener, final Optional currentState) { if(currentState.isPresent()) { - ShardDataTreeChangePublisher localTreeChangePublisher = new ShardDataTreeChangePublisher(); - localTreeChangePublisher.registerTreeChangeListener(path, listener); - localTreeChangePublisher.publishChanges(currentState.get()); + ShardDataTreeChangeListenerPublisher localPublisher = treeChangeListenerPublisher.newInstance(); + localPublisher.registerTreeChangeListener(path, listener); + localPublisher.publishChanges(currentState.get(), logContext); } } @@ -143,7 +148,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { if (chain != null) { chain.close(); } else { - LOG.debug("Closing non-existent transaction chain {}", transactionChainId); + LOG.debug("{}: Closing non-existent transaction chain {}", logContext, transactionChainId); } } @@ -152,7 +157,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { final AsyncDataChangeListener> listener, final DataChangeScope scope) { final DataChangeListenerRegistration>> reg = - listenerTree.registerDataChangeListener(path, listener, scope); + dataChangeListenerPublisher.registerDataChangeListener(path, listener, scope); return new SimpleEntry<>(reg, readCurrentData()); } @@ -165,20 +170,20 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { public Entry, Optional> registerTreeChangeListener( final YangInstanceIdentifier path, final DOMDataTreeChangeListener listener) { - final ListenerRegistration reg = treeChangePublisher.registerTreeChangeListener( + final ListenerRegistration reg = treeChangeListenerPublisher.registerTreeChangeListener( path, listener); return new SimpleEntry<>(reg, readCurrentData()); } void applyForeignCandidate(final String identifier, final DataTreeCandidate foreign) throws DataValidationFailedException { - LOG.debug("Applying foreign transaction {}", identifier); + LOG.debug("{}: Applying foreign transaction {}", logContext, identifier); final DataTreeModification mod = dataTree.takeSnapshot().newModification(); DataTreeCandidates.applyToModification(mod, foreign); mod.ready(); - LOG.trace("Applying foreign modification {}", mod); + LOG.trace("{}: Applying foreign modification {}", logContext, mod); dataTree.validate(mod); final DataTreeCandidate candidate = dataTree.prepare(mod); dataTree.commit(candidate); @@ -196,4 +201,24 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { snapshot.ready(); return new SimpleShardDataTreeCohort(this, snapshot, transaction.getId()); } + + public Optional> readNode(YangInstanceIdentifier path) { + return dataTree.takeSnapshot().readNode(path); + } + + public DataTreeSnapshot takeSnapshot() { + return dataTree.takeSnapshot(); + } + + public DataTreeModification newModification() { + return dataTree.takeSnapshot().newModification(); + } + + public DataTreeCandidate commit(DataTreeModification modification) throws DataValidationFailedException { + modification.ready(); + dataTree.validate(modification); + DataTreeCandidateTip candidate = dataTree.prepare(modification); + dataTree.commit(candidate); + return candidate; + } }