- return debugTransactions;
- }
-
- final DataTreeSnapshot takeSnapshot() {
- return dataTree.takeSnapshot();
- }
-
- @Override
- public <L extends AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>> ListenerRegistration<L> registerChangeListener(
- final YangInstanceIdentifier path, final L listener, final DataChangeScope scope) {
-
- /*
- * Make sure commit is not occurring right now. Listener has to be
- * registered and its state capture enqueued at a consistent point.
- *
- * FIXME: improve this to read-write lock, such that multiple listener
- * registrations can occur simultaneously
- */
- final DataChangeListenerRegistration<L> reg;
- synchronized (this) {
- LOG.debug("{}: Registering data change listener {} for {}", name, listener, path);
-
- reg = listenerTree.registerDataChangeListener(path, listener, scope);
-
- Optional<NormalizedNode<?, ?>> currentState = dataTree.takeSnapshot().readNode(path);
- if (currentState.isPresent()) {
- final NormalizedNode<?, ?> data = currentState.get();
-
- final DOMImmutableDataChangeEvent event = DOMImmutableDataChangeEvent.builder(DataChangeScope.BASE) //
- .setAfter(data) //
- .addCreated(path, data) //
- .build();
-
- dataChangeListenerNotificationManager.submitNotification(reg, event);
- }
- }
-
- return new AbstractListenerRegistration<L>(listener) {
- @Override
- protected void removeRegistration() {
- synchronized (InMemoryDOMDataStore.this) {
- reg.close();
- }
- }
- };
- }
-
- @Override
- public synchronized <L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerTreeChangeListener(final YangInstanceIdentifier treeId, final L listener) {
- /*
- * Make sure commit is not occurring right now. Listener has to be
- * registered and its state capture enqueued at a consistent point.
- */
- return changePublisher.registerTreeChangeListener(treeId, listener, dataTree.takeSnapshot());
- }
-
- @Override
- protected void transactionAborted(final SnapshotBackedWriteTransaction<String> tx) {
- LOG.debug("Tx: {} is closed.", tx.getIdentifier());
- }
-
- @Override
- protected DOMStoreThreePhaseCommitCohort transactionReady(final SnapshotBackedWriteTransaction<String> tx, final DataTreeModification modification) {
- LOG.debug("Tx: {} is submitted. Modifications: {}", tx.getIdentifier(), modification);
- return new InMemoryDOMStoreThreePhaseCommitCohort(this, tx, modification);
- }
-
- String nextIdentifier() {
- return name + "-" + txCounter.getAndIncrement();
- }
-
- void validate(final DataTreeModification modification) throws DataValidationFailedException {
- dataTree.validate(modification);
- }
-
- DataTreeCandidate prepare(final DataTreeModification modification) {
- return dataTree.prepare(modification);
- }
-
- synchronized void commit(final DataTreeCandidate candidate) {
- dataTree.commit(candidate);
- changePublisher.publishChange(candidate);
- ResolveDataChangeEventsTask.create(candidate, listenerTree).resolve(dataChangeListenerNotificationManager);