Bump versions to 4.0.0-SNAPSHOT
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / sharding / DistributedShardChangePublisher.java
index 0e7216f3c79867b282c03d57ca6339540fb1833d..db8e1edebde2e6a2d3f1b72253e6d5a1f27e263e 100644 (file)
@@ -17,12 +17,11 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 import org.checkerframework.checker.lock.qual.GuardedBy;
 import org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient;
-import org.opendaylight.controller.cluster.datastore.AbstractDataStore;
+import org.opendaylight.controller.cluster.datastore.DistributedDataStoreInterface;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.mdsal.dom.spi.AbstractDOMDataTreeChangeListenerRegistration;
@@ -33,27 +32,27 @@ import org.opendaylight.mdsal.dom.spi.store.DOMStoreTreeChangePublisher;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNodes;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
 import org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaValidationFailedException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Deprecated(forRemoval = true)
 public class DistributedShardChangePublisher
         extends AbstractRegistrationTree<AbstractDOMDataTreeChangeListenerRegistration<?>>
         implements DOMStoreTreeChangePublisher {
 
     private static final Logger LOG = LoggerFactory.getLogger(DistributedShardChangePublisher.class);
 
-    private final AbstractDataStore distributedDataStore;
+    private final DistributedDataStoreInterface distributedDataStore;
     private final YangInstanceIdentifier shardPath;
 
     private final Map<DOMDataTreeIdentifier, ChildShardContext> childShards;
@@ -62,7 +61,7 @@ public class DistributedShardChangePublisher
     private final DataTree dataTree;
 
     public DistributedShardChangePublisher(final DataStoreClient client,
-                                           final AbstractDataStore distributedDataStore,
+                                           final DistributedDataStoreInterface distributedDataStore,
                                            final DOMDataTreeIdentifier prefix,
                                            final Map<DOMDataTreeIdentifier, ChildShardContext> childShards) {
         this.distributedDataStore = distributedDataStore;
@@ -89,7 +88,7 @@ public class DistributedShardChangePublisher
                 .build());
 
         // XXX: can we guarantee that the root is present in the schemacontext?
-        this.dataTree.setSchemaContext(distributedDataStore.getActorUtils().getSchemaContext());
+        this.dataTree.setEffectiveModelContext(distributedDataStore.getActorUtils().getSchemaContext());
         this.shardPath = prefix.getRootIdentifier();
         this.childShards = childShards;
     }
@@ -158,7 +157,7 @@ public class DistributedShardChangePublisher
 
         @SuppressWarnings("unchecked")
         final AbstractDOMDataTreeChangeListenerRegistration<L> registration =
-            new AbstractDOMDataTreeChangeListenerRegistration<L>((L) listener) {
+            new AbstractDOMDataTreeChangeListenerRegistration<>((L) listener) {
                 @Override
                 protected void removeRegistration() {
                     listener.close();
@@ -218,11 +217,12 @@ public class DistributedShardChangePublisher
         DataTreeCandidateNode modifiedChild = candidate.getRootNode();
 
         for (final PathArgument pathArgument : listenerPath.getPathArguments()) {
-            modifiedChild = modifiedChild.getModifiedChild(pathArgument);
+            modifiedChild = modifiedChild.getModifiedChild(pathArgument).orElse(null);
         }
 
+
         if (modifiedChild == null) {
-            modifiedChild = new EmptyDataTreeCandidateNode(dataTree.getRootPath().getLastPathArgument());
+            modifiedChild = DataTreeCandidateNodes.empty(dataTree.getRootPath().getLastPathArgument());
         }
 
         return DataTreeCandidates.newDataTreeCandidate(dataTree.getRootPath(), modifiedChild);
@@ -317,44 +317,4 @@ public class DistributedShardChangePublisher
             registrations.clear();
         }
     }
-
-    private static final class EmptyDataTreeCandidateNode implements DataTreeCandidateNode {
-
-        private final PathArgument identifier;
-
-        EmptyDataTreeCandidateNode(final PathArgument identifier) {
-            this.identifier = requireNonNull(identifier, "Identifier should not be null");
-        }
-
-        @Override
-        public PathArgument getIdentifier() {
-            return identifier;
-        }
-
-        @Override
-        public Collection<DataTreeCandidateNode> getChildNodes() {
-            return Collections.emptySet();
-        }
-
-        @Override
-        @SuppressWarnings("checkstyle:hiddenField")
-        public DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
-            return null;
-        }
-
-        @Override
-        public ModificationType getModificationType() {
-            return ModificationType.UNMODIFIED;
-        }
-
-        @Override
-        public Optional<NormalizedNode<?, ?>> getDataAfter() {
-            return Optional.empty();
-        }
-
-        @Override
-        public Optional<NormalizedNode<?, ?>> getDataBefore() {
-            return Optional.empty();
-        }
-    }
 }