X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fstore%2Fimpl%2FInMemoryDOMDataStore.java;h=9bbba1e24d8600f196f23df145105d1b787e9c6e;hp=de0c1463923ebe0e2600a79191e590cf7552376f;hb=84248dac9ed8aa37e996e39429c8aa8ece473eaf;hpb=87aaa33c37ebf91368d23fc5f8f4916265d43712 diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java index de0c146392..9bbba1e24d 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java @@ -18,8 +18,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.ListenerRegistrationNode; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.ListenerRegistrationNode.DataChangeListenerRegistration; +import org.opendaylight.controller.md.sal.dom.store.impl.tree.ListenerTree; import org.opendaylight.controller.md.sal.dom.store.impl.tree.ModificationType; import org.opendaylight.controller.md.sal.dom.store.impl.tree.NodeModification; import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreMetadataNode; @@ -59,7 +58,7 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch private final ListeningExecutorService executor; private final String name; private final AtomicLong txCounter = new AtomicLong(0); - private final ListenerRegistrationNode listenerTree; + private final ListenerTree listenerTree; private final AtomicReference snapshot; private ModificationApplyOperation operationTree; @@ -69,7 +68,7 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch public InMemoryDOMDataStore(final String name, final ListeningExecutorService executor) { this.name = Preconditions.checkNotNull(name); this.executor = Preconditions.checkNotNull(executor); - this.listenerTree = ListenerRegistrationNode.createRoot(); + this.listenerTree = ListenerTree.create(); this.snapshot = new AtomicReference(DataAndMetadataSnapshot.createEmpty()); this.operationTree = new AlwaysFailOperation(); } @@ -114,18 +113,14 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch final DataChangeListenerRegistration reg; synchronized (this) { LOG.debug("{}: Registering data change listener {} for {}",name,listener,path); - ListenerRegistrationNode listenerNode = listenerTree; - for(PathArgument arg : path.getPath()) { - listenerNode = listenerNode.ensureChild(arg); - } - reg = listenerNode.registerDataChangeListener(path, listener, scope); + reg = listenerTree.registerDataChangeListener(path, listener, scope); Optional currentState = snapshot.get().read(path); if (currentState.isPresent()) { final NormalizedNode data = currentState.get().getData(); - final DOMImmutableDataChangeEvent event = DOMImmutableDataChangeEvent.builder() // + final DOMImmutableDataChangeEvent event = DOMImmutableDataChangeEvent.builder(DataChangeScope.BASE) // .setAfter(data) // .addCreated(path, data) // .build(); @@ -154,7 +149,7 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch } private void commit(final DataAndMetadataSnapshot currentSnapshot, - final StoreMetadataNode newDataTree, final DataChangeEventResolver listenerResolver) { + final StoreMetadataNode newDataTree, final ResolveDataChangeEventsTask listenerResolver) { LOG.debug("Updating Store snaphot version: {} with version:{}",currentSnapshot.getMetadataTree().getSubtreeVersion(),newDataTree.getSubtreeVersion()); if(LOG.isTraceEnabled()) { @@ -173,7 +168,8 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch final boolean success = snapshot.compareAndSet(currentSnapshot, newSnapshot); checkState(success, "Store snapshot and transaction snapshot differ. This should never happen."); - for (ChangeListenerNotifyTask task : listenerResolver.resolve()) { + for (ChangeListenerNotifyTask task : listenerResolver.call()) { + LOG.trace("Scheduling invocation of listeners: {}",task); executor.submit(task); } } @@ -253,13 +249,37 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch @Override public void write(final InstanceIdentifier path, final NormalizedNode data) { checkNotReady(); - mutableTree.write(path, data); + try { + LOG.trace("Tx: {} Write: {}:{}",getIdentifier(),path,data); + mutableTree.write(path, data); + // FIXME: Add checked exception + } catch (Exception e) { + LOG.error("Tx: {}, failed to write {}:{} in {}",getIdentifier(),path,data,mutableTree,e); + } + } + + @Override + public void merge(final InstanceIdentifier path, final NormalizedNode data) { + checkNotReady(); + try { + LOG.trace("Tx: {} Merge: {}:{}",getIdentifier(),path,data); + mutableTree.merge(path, data); + // FIXME: Add checked exception + } catch (Exception e) { + LOG.error("Tx: {}, failed to write {}:{} in {}",getIdentifier(),path,data,mutableTree,e); + } } @Override public void delete(final InstanceIdentifier path) { checkNotReady(); - mutableTree.delete(path); + try { + LOG.trace("Tx: {} Delete: {}",getIdentifier(),path); + mutableTree.delete(path); + // FIXME: Add checked exception + } catch (Exception e) { + LOG.error("Tx: {}, failed to delete {} in {}",getIdentifier(),path,mutableTree,e); + } } protected final boolean isReady() { @@ -300,7 +320,13 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch @Override public ListenableFuture>> read(final InstanceIdentifier path) { - return Futures.immediateFuture(getMutatedView().read(path)); + LOG.trace("Tx: {} Read: {}",getIdentifier(),path); + try { + return Futures.immediateFuture(getMutatedView().read(path)); + } catch (Exception e) { + LOG.error("Tx: {} Failed Read of {}",getIdentifier(),path,e); + throw e; + } } } @@ -311,7 +337,7 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch private DataAndMetadataSnapshot storeSnapshot; private Optional proposedSubtree; - private DataChangeEventResolver listenerResolver; + private ResolveDataChangeEventsTask listenerResolver; public ThreePhaseCommitImpl(final SnaphostBackedWriteTransaction writeTransaction) { this.transaction = writeTransaction; @@ -352,7 +378,7 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch proposedSubtree = operationTree.apply(modification, Optional.of(metadataTree), increase(metadataTree.getSubtreeVersion())); - listenerResolver = DataChangeEventResolver.create() // + listenerResolver = ResolveDataChangeEventsTask.create() // .setRootPath(PUBLIC_ROOT_PATH) // .setBeforeRoot(Optional.of(metadataTree)) // .setAfterRoot(proposedSubtree) //