Use singleton NodeIdentifierWithPredicates
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / SimpleShardDataTreeCohort.java
index 3104cb4972de5973f270ceb32593fd809bb58088..f42af0b88e5847c3201520cfbca632b4b2da4dcd 100644 (file)
@@ -7,13 +7,17 @@
  */
 package org.opendaylight.controller.cluster.datastore;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Verify;
 import com.google.common.primitives.UnsignedLong;
 import com.google.common.util.concurrent.FutureCallback;
 import java.util.Optional;
+import java.util.SortedSet;
 import java.util.concurrent.CompletionStage;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip;
@@ -28,6 +32,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
     private final ShardDataTree dataTree;
     private final TransactionIdentifier transactionId;
     private final CompositeDataTreeCohort userCohorts;
+    private final @Nullable SortedSet<String> participatingShardNames;
 
     private State state = State.READY;
     private DataTreeCandidateTip candidate;
@@ -35,20 +40,23 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
     private Exception nextFailure;
 
     SimpleShardDataTreeCohort(final ShardDataTree dataTree, final DataTreeModification transaction,
-            final TransactionIdentifier transactionId, final CompositeDataTreeCohort userCohorts) {
-        this.dataTree = Preconditions.checkNotNull(dataTree);
-        this.transaction = Preconditions.checkNotNull(transaction);
-        this.transactionId = Preconditions.checkNotNull(transactionId);
-        this.userCohorts = Preconditions.checkNotNull(userCohorts);
+            final TransactionIdentifier transactionId, final CompositeDataTreeCohort userCohorts,
+            final Optional<SortedSet<String>> participatingShardNames) {
+        this.dataTree = requireNonNull(dataTree);
+        this.transaction = requireNonNull(transaction);
+        this.transactionId = requireNonNull(transactionId);
+        this.userCohorts = requireNonNull(userCohorts);
+        this.participatingShardNames = requireNonNull(participatingShardNames).orElse(null);
     }
 
     SimpleShardDataTreeCohort(final ShardDataTree dataTree, final DataTreeModification transaction,
         final TransactionIdentifier transactionId, final Exception nextFailure) {
-        this.dataTree = Preconditions.checkNotNull(dataTree);
-        this.transaction = Preconditions.checkNotNull(transaction);
-        this.transactionId = Preconditions.checkNotNull(transactionId);
+        this.dataTree = requireNonNull(dataTree);
+        this.transaction = requireNonNull(transaction);
+        this.transactionId = requireNonNull(transactionId);
         this.userCohorts = null;
-        this.nextFailure = Preconditions.checkNotNull(nextFailure);
+        this.participatingShardNames = null;
+        this.nextFailure = requireNonNull(nextFailure);
     }
 
     @Override
@@ -66,8 +74,14 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
         return transaction;
     }
 
+    @Override
+    Optional<SortedSet<String>> getParticipatingShardNames() {
+        return Optional.ofNullable(participatingShardNames);
+    }
+
     private void checkState(final State expected) {
-        Preconditions.checkState(state == expected, "State %s does not match expected state %s", state, expected);
+        Preconditions.checkState(state == expected, "State %s does not match expected state %s for %s",
+                state, expected, getIdentifier());
     }
 
     @Override
@@ -77,7 +91,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
         }
 
         checkState(State.READY);
-        this.callback = Preconditions.checkNotNull(newCallback);
+        this.callback = requireNonNull(newCallback);
         state = State.CAN_COMMIT_PENDING;
 
         if (nextFailure == null) {
@@ -90,7 +104,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
     @Override
     public void preCommit(final FutureCallback<DataTreeCandidate> newCallback) {
         checkState(State.CAN_COMMIT_COMPLETE);
-        this.callback = Preconditions.checkNotNull(newCallback);
+        this.callback = requireNonNull(newCallback);
         state = State.PRE_COMMIT_PENDING;
 
         if (nextFailure == null) {
@@ -128,7 +142,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
     @Override
     public void commit(final FutureCallback<UnsignedLong> newCallback) {
         checkState(State.PRE_COMMIT_COMPLETE);
-        this.callback = Preconditions.checkNotNull(newCallback);
+        this.callback = requireNonNull(newCallback);
         state = State.COMMIT_PENDING;
 
         if (nextFailure == null) {
@@ -257,7 +271,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
 
     void reportFailure(final Exception cause) {
         if (nextFailure == null) {
-            this.nextFailure = Preconditions.checkNotNull(cause);
+            this.nextFailure = requireNonNull(cause);
         } else {
             LOG.debug("Transaction {} already has a set failure, not updating it", transactionId, cause);
         }