Cleanup warnings
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / DataTreeCohortActorRegistry.java
index f79c0475bb73afc025545704ac590ab058961723..0e149fa91cc9800e177a3483ae272b2c16d48c10 100644 (file)
@@ -13,15 +13,15 @@ import akka.actor.PoisonPill;
 import akka.actor.Status;
 import akka.util.Timeout;
 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.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.concurrent.NotThreadSafe;
 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
-import org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit;
 import org.opendaylight.controller.md.sal.dom.spi.AbstractRegistrationTree;
 import org.opendaylight.controller.md.sal.dom.spi.RegistrationTreeNode;
 import org.opendaylight.controller.md.sal.dom.spi.RegistrationTreeSnapshot;
@@ -50,7 +50,7 @@ class DataTreeCohortActorRegistry extends AbstractRegistrationTree<ActorRef> {
     private final Map<ActorRef, RegistrationTreeNode<ActorRef>> cohortToNode = new HashMap<>();
 
     Collection<ActorRef> getCohortActors() {
-        return Collections.unmodifiableCollection(cohortToNode.keySet());
+        return new ArrayList<>(cohortToNode.keySet());
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
@@ -82,7 +82,7 @@ class DataTreeCohortActorRegistry extends AbstractRegistrationTree<ActorRef> {
         cohort.tell(PoisonPill.getInstance(), cohort);
     }
 
-    Collection<DataTreeCohortActor.CanCommit> createCanCommitMessages(final TransactionIdentifier txId,
+    List<DataTreeCohortActor.CanCommit> createCanCommitMessages(final TransactionIdentifier txId,
             final DataTreeCandidate candidate, final SchemaContext schema) {
         try (RegistrationTreeSnapshot<ActorRef> cohorts = takeSnapshot()) {
             return new CanCommitMessageBuilder(txId, candidate, schema).perform(cohorts.getRootNode());
@@ -139,8 +139,7 @@ class DataTreeCohortActorRegistry extends AbstractRegistrationTree<ActorRef> {
         private final TransactionIdentifier txId;
         private final DataTreeCandidate candidate;
         private final SchemaContext schema;
-        private final Collection<DataTreeCohortActor.CanCommit> messages =
-                new ArrayList<>();
+        private final Multimap<ActorRef, DOMDataTreeCandidate> actorToCandidates = ArrayListMultimap.create();
 
         CanCommitMessageBuilder(final TransactionIdentifier txId, final DataTreeCandidate candidate,
                 final SchemaContext schema) {
@@ -197,8 +196,7 @@ class DataTreeCohortActorRegistry extends AbstractRegistrationTree<ActorRef> {
                 final DataTreeCandidateNode node) {
             final DOMDataTreeCandidate domCandidate = DOMDataTreeCandidateTO.create(treeIdentifier(path), node);
             for (final ActorRef reg : regs) {
-                final CanCommit message = new DataTreeCohortActor.CanCommit(txId, domCandidate, schema, reg);
-                messages.add(message);
+                actorToCandidates.put(reg, domCandidate);
             }
         }
 
@@ -206,9 +204,16 @@ class DataTreeCohortActorRegistry extends AbstractRegistrationTree<ActorRef> {
             return new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, path);
         }
 
-        private Collection<DataTreeCohortActor.CanCommit> perform(final RegistrationTreeNode<ActorRef> rootNode) {
+        List<DataTreeCohortActor.CanCommit> perform(final RegistrationTreeNode<ActorRef> rootNode) {
             final List<PathArgument> toLookup = candidate.getRootPath().getPathArguments();
             lookupAndCreateCanCommits(toLookup, 0, rootNode);
+
+            final Map<ActorRef, Collection<DOMDataTreeCandidate>> mapView = actorToCandidates.asMap();
+            final List<DataTreeCohortActor.CanCommit> messages = new ArrayList<>(mapView.size());
+            for (Map.Entry<ActorRef, Collection<DOMDataTreeCandidate>> entry: mapView.entrySet()) {
+                messages.add(new DataTreeCohortActor.CanCommit(txId, entry.getValue(), schema, entry.getKey()));
+            }
+
             return messages;
         }
     }