X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-inmemory-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fstore%2Fimpl%2FResolveDataChangeEventsTask.java;h=fb4931098b34776cf334af7ef835323e915661a2;hp=a4e8c86aa83f1b10f084f86f81a10feb08178d58;hb=1e884647502a8d91f8a57bde8193c60b9bbcce0d;hpb=d5a00419b66920905e68ff857f44d3a0ab417db7 diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeEventsTask.java b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeEventsTask.java index a4e8c86aa8..fb4931098b 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeEventsTask.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeEventsTask.java @@ -11,19 +11,13 @@ import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; - -import java.util.ArrayList; import java.util.Collection; import java.util.Map.Entry; -import java.util.concurrent.Callable; - import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener; +import org.opendaylight.controller.md.sal.dom.spi.RegistrationTreeSnapshot; import org.opendaylight.controller.md.sal.dom.store.impl.DOMImmutableDataChangeEvent.Builder; import org.opendaylight.controller.md.sal.dom.store.impl.DOMImmutableDataChangeEvent.SimpleEventFactory; import org.opendaylight.controller.md.sal.dom.store.impl.tree.ListenerTree; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.ListenerTree.Walker; import org.opendaylight.yangtools.util.concurrent.NotificationManager; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; @@ -40,36 +34,24 @@ import org.slf4j.LoggerFactory; * Computes data change events for all affected registered listeners in data * tree. */ -final class ResolveDataChangeEventsTask implements Callable> { +final class ResolveDataChangeEventsTask { private static final Logger LOG = LoggerFactory.getLogger(ResolveDataChangeEventsTask.class); - @SuppressWarnings("rawtypes") - private final NotificationManager notificationMgr; private final DataTreeCandidate candidate; private final ListenerTree listenerRoot; private Multimap, DOMImmutableDataChangeEvent> collectedEvents; - @SuppressWarnings("rawtypes") - public ResolveDataChangeEventsTask(final DataTreeCandidate candidate, final ListenerTree listenerTree, - final NotificationManager notificationMgr) { + public ResolveDataChangeEventsTask(final DataTreeCandidate candidate, final ListenerTree listenerTree) { this.candidate = Preconditions.checkNotNull(candidate); this.listenerRoot = Preconditions.checkNotNull(listenerTree); - this.notificationMgr = Preconditions.checkNotNull(notificationMgr); } /** - * Resolves and creates Notification Tasks - * - * Implementation of done as Map-Reduce with two steps: 1. resolving events - * and their mapping to listeners 2. merging events affecting same listener - * - * @return An {@link Iterable} of Notification Tasks which needs to be executed in - * order to delivery data change events. + * Resolves and submits notification tasks to the specified manager. */ - @Override - public synchronized Iterable call() { - try (final Walker w = listenerRoot.getWalker()) { + public synchronized void resolve(final NotificationManager, DOMImmutableDataChangeEvent> manager) { + try (final RegistrationTreeSnapshot> w = listenerRoot.takeSnapshot()) { // Defensive: reset internal state collectedEvents = ArrayListMultimap.create(); @@ -81,7 +63,6 @@ final class ResolveDataChangeEventsTask implements Callable ret = new ArrayList<>(); for (Entry, Collection> e : collectedEvents.asMap().entrySet()) { final Collection col = e.getValue(); final DOMImmutableDataChangeEvent event; @@ -98,12 +79,8 @@ final class ResolveDataChangeEventsTask implements Callable> maybeBefore = node.getDataBefore(); + final Optional> maybeAfter = node.getDataAfter(); + final ModificationType type = node.getModificationType(); + + if (type != ModificationType.UNMODIFIED && !maybeAfter.isPresent() && !maybeBefore.isPresent()) { LOG.debug("Modification at {} has type {}, but no before- and after-data. Assuming unchanged.", - state.getPath(), node.getModificationType()); + state.getPath(), type); return false; } // no before and after state is present - switch (node.getModificationType()) { + switch (type) { case SUBTREE_MODIFIED: return resolveSubtreeChangeEvent(state, node); case MERGE: case WRITE: - Preconditions.checkArgument(node.getDataAfter().isPresent(), - "Modification at {} has type {} but no after-data", state.getPath(), node.getModificationType()); - if (!node.getDataBefore().isPresent()) { - resolveCreateEvent(state, node.getDataAfter().get()); + Preconditions.checkArgument(maybeAfter.isPresent(), + "Modification at {} has type {} but no after-data", state.getPath(), type); + if (!maybeBefore.isPresent()) { + @SuppressWarnings({ "unchecked", "rawtypes" }) + final NormalizedNode afterNode = (NormalizedNode)maybeAfter.get(); + resolveSameEventRecursivelly(state, afterNode, DOMImmutableDataChangeEvent.getCreateEventFactory()); return true; } - return resolveReplacedEvent(state, node.getDataBefore().get(), node.getDataAfter().get()); + return resolveReplacedEvent(state, maybeBefore.get(), maybeAfter.get()); case DELETE: - Preconditions.checkArgument(node.getDataBefore().isPresent(), - "Modification at {} has type {} but no before-data", state.getPath(), node.getModificationType()); - resolveDeleteEvent(state, node.getDataBefore().get()); + Preconditions.checkArgument(maybeBefore.isPresent(), + "Modification at {} has type {} but no before-data", state.getPath(), type); + + @SuppressWarnings({ "unchecked", "rawtypes" }) + final NormalizedNode beforeNode = (NormalizedNode)maybeBefore.get(); + resolveSameEventRecursivelly(state, beforeNode, DOMImmutableDataChangeEvent.getRemoveEventFactory()); return true; case UNMODIFIED: return false; } - throw new IllegalStateException(String.format("Unhandled node state %s at %s", node.getModificationType(), state.getPath())); + throw new IllegalStateException(String.format("Unhandled node state %s at %s", type, state.getPath())); } private boolean resolveReplacedEvent(final ResolveDataChangeState state, @@ -244,26 +229,6 @@ final class ResolveDataChangeEventsTask implements Callable afterState) { - @SuppressWarnings({ "unchecked", "rawtypes" }) - final NormalizedNode node = (NormalizedNode) afterState; - resolveSameEventRecursivelly(state, node, DOMImmutableDataChangeEvent.getCreateEventFactory()); - } - - private void resolveDeleteEvent(final ResolveDataChangeState state, final NormalizedNode beforeState) { - @SuppressWarnings({ "unchecked", "rawtypes" }) - final NormalizedNode node = (NormalizedNode) beforeState; - resolveSameEventRecursivelly(state, node, DOMImmutableDataChangeEvent.getRemoveEventFactory()); - } - private void resolveSameEventRecursivelly(final ResolveDataChangeState state, final NormalizedNode node, final SimpleEventFactory eventFactory) { if (!state.needsProcessing()) { @@ -295,8 +260,16 @@ final class ResolveDataChangeEventsTask implements Callable> maybeBefore = modification.getDataBefore(); + final Optional> maybeAfter = modification.getDataAfter(); + + Preconditions.checkArgument(maybeBefore.isPresent(), "Subtree change with before-data not present at path %s", state.getPath()); + Preconditions.checkArgument(maybeAfter.isPresent(), "Subtree change with after-data not present at path %s", state.getPath()); + + if (!state.needsProcessing()) { + LOG.trace("Not processing modified subtree {}", state.getPath()); + return true; + } DataChangeScope scope = null; for (DataTreeCandidateNode childMod : modification.getChildNodes()) { @@ -321,8 +294,8 @@ final class ResolveDataChangeEventsTask implements Callable before = modification.getDataBefore().get(); - final NormalizedNode after = modification.getDataAfter().get(); + final NormalizedNode before = maybeBefore.get(); + final NormalizedNode after = maybeAfter.get(); if (scope != null) { DOMImmutableDataChangeEvent one = DOMImmutableDataChangeEvent.builder(scope).addUpdated(state.getPath(), before, after).build(); @@ -333,10 +306,7 @@ final class ResolveDataChangeEventsTask implements Callable notificationMgr) { - return new ResolveDataChangeEventsTask(candidate, listenerTree, notificationMgr); + public static ResolveDataChangeEventsTask create(final DataTreeCandidate candidate, final ListenerTree listenerTree) { + return new ResolveDataChangeEventsTask(candidate, listenerTree); } }