Add OnDemandShardState to report additional Shard state
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / DataTreeCohortActor.java
index 485e8b5c2496711506cec4459708067e849cd6d7..e6ff10d8315cd47da347ae4764d20c7b825b51eb 100644 (file)
@@ -12,28 +12,29 @@ import akka.actor.ActorRef;
 import akka.actor.Props;
 import akka.actor.Status;
 import com.google.common.base.Preconditions;
+import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor;
 import org.opendaylight.mdsal.common.api.PostCanCommitStep;
 import org.opendaylight.mdsal.common.api.PostPreCommitStep;
 import org.opendaylight.mdsal.common.api.ThreePhaseCommitStep;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeCandidate;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohort;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Proxy actor which acts as a facade to the user-provided commit cohort. Responsible for
  * decapsulating DataTreeChanged messages and dispatching their context to the user.
  */
 final class DataTreeCohortActor extends AbstractUntypedActor {
-    private static final Logger LOG = LoggerFactory.getLogger(DataTreeCohortActor.class);
     private final CohortBehaviour<?> idleState = new Idle();
     private final DOMDataTreeCommitCohort cohort;
+    private final YangInstanceIdentifier registeredPath;
     private CohortBehaviour<?> currentState = idleState;
 
-    private DataTreeCohortActor(final DOMDataTreeCommitCohort cohort) {
+    private DataTreeCohortActor(final DOMDataTreeCommitCohort cohort, final YangInstanceIdentifier registeredPath) {
         this.cohort = Preconditions.checkNotNull(cohort);
+        this.registeredPath = Preconditions.checkNotNull(registeredPath);
     }
 
     @Override
@@ -47,15 +48,15 @@ final class DataTreeCohortActor extends AbstractUntypedActor {
      *
      * @param <R> Reply message type
      */
-    static abstract class CommitProtocolCommand<R extends CommitReply> {
+    abstract static class CommitProtocolCommand<R extends CommitReply> {
 
-        private final String txId;
+        private final TransactionIdentifier txId;
 
-        final String getTxId() {
+        final TransactionIdentifier getTxId() {
             return txId;
         }
 
-        protected CommitProtocolCommand(String txId) {
+        protected CommitProtocolCommand(TransactionIdentifier txId) {
             this.txId = Preconditions.checkNotNull(txId);
         }
     }
@@ -66,7 +67,7 @@ final class DataTreeCohortActor extends AbstractUntypedActor {
         private final ActorRef cohort;
         private final SchemaContext schema;
 
-        CanCommit(String txId, DOMDataTreeCandidate candidate, SchemaContext schema, ActorRef cohort) {
+        CanCommit(TransactionIdentifier txId, DOMDataTreeCandidate candidate, SchemaContext schema, ActorRef cohort) {
             super(txId);
             this.cohort = Preconditions.checkNotNull(cohort);
             this.candidate = Preconditions.checkNotNull(candidate);
@@ -87,12 +88,12 @@ final class DataTreeCohortActor extends AbstractUntypedActor {
 
     }
 
-    static abstract class CommitReply {
+    abstract static class CommitReply {
 
         private final ActorRef cohortRef;
-        private final String txId;
+        private final TransactionIdentifier txId;
 
-        protected CommitReply(ActorRef cohortRef, String txId) {
+        protected CommitReply(ActorRef cohortRef, TransactionIdentifier txId) {
             this.cohortRef = Preconditions.checkNotNull(cohortRef);
             this.txId = Preconditions.checkNotNull(txId);
         }
@@ -101,15 +102,14 @@ final class DataTreeCohortActor extends AbstractUntypedActor {
             return cohortRef;
         }
 
-        final String getTxId() {
+        final TransactionIdentifier getTxId() {
             return txId;
         }
-
     }
 
     static final class Success extends CommitReply {
 
-        public Success(ActorRef cohortRef, String txId) {
+        Success(ActorRef cohortRef, TransactionIdentifier txId) {
             super(cohortRef, txId);
         }
 
@@ -117,26 +117,26 @@ final class DataTreeCohortActor extends AbstractUntypedActor {
 
     static final class PreCommit extends CommitProtocolCommand<Success> {
 
-        public PreCommit(String txId) {
+        PreCommit(TransactionIdentifier txId) {
             super(txId);
         }
     }
 
     static final class Abort extends CommitProtocolCommand<Success> {
 
-        public Abort(String txId) {
+        Abort(TransactionIdentifier txId) {
             super(txId);
         }
     }
 
     static final class Commit extends CommitProtocolCommand<Success> {
 
-        public Commit(String txId) {
+        Commit(TransactionIdentifier txId) {
             super(txId);
         }
     }
 
-    private static abstract class CohortBehaviour<E> {
+    private abstract static class CohortBehaviour<E> {
 
         abstract Class<E> getHandledMessageType();
 
@@ -146,7 +146,8 @@ final class DataTreeCohortActor extends AbstractUntypedActor {
             } else if (message instanceof Abort) {
                 return abort();
             }
-            throw new UnsupportedOperationException();
+            throw new UnsupportedOperationException(String.format("Unexpected message %s in cohort behavior %s",
+                    message.getClass(), getClass().getSimpleName()));
         }
 
         abstract CohortBehaviour<?> abort();
@@ -163,6 +164,7 @@ final class DataTreeCohortActor extends AbstractUntypedActor {
         }
 
         @Override
+        @SuppressWarnings("checkstyle:IllegalCatch")
         CohortBehaviour<?> process(CanCommit message) {
             final PostCanCommitStep nextStep;
             try {
@@ -187,9 +189,9 @@ final class DataTreeCohortActor extends AbstractUntypedActor {
             extends CohortBehaviour<M> {
 
         private final S step;
-        private final String txId;
+        private final TransactionIdentifier txId;
 
-        CohortStateWithStep(String txId, S step) {
+        CohortStateWithStep(TransactionIdentifier txId, S step) {
             this.txId = Preconditions.checkNotNull(txId);
             this.step = Preconditions.checkNotNull(step);
         }
@@ -198,11 +200,12 @@ final class DataTreeCohortActor extends AbstractUntypedActor {
             return step;
         }
 
-        final String getTxId() {
+        final TransactionIdentifier getTxId() {
             return txId;
         }
 
         @Override
+        @SuppressWarnings("checkstyle:IllegalCatch")
         final CohortBehaviour<?> abort() {
             try {
                 getStep().abort().get();
@@ -219,7 +222,7 @@ final class DataTreeCohortActor extends AbstractUntypedActor {
 
     private class PostCanCommit extends CohortStateWithStep<PreCommit, PostCanCommitStep> {
 
-        PostCanCommit(String txId, PostCanCommitStep nextStep) {
+        PostCanCommit(TransactionIdentifier txId, PostCanCommitStep nextStep) {
             super(txId, nextStep);
         }
 
@@ -229,6 +232,7 @@ final class DataTreeCohortActor extends AbstractUntypedActor {
         }
 
         @Override
+        @SuppressWarnings("checkstyle:IllegalCatch")
         CohortBehaviour<?> process(PreCommit message) {
             final PostPreCommitStep nextStep;
             try {
@@ -245,11 +249,12 @@ final class DataTreeCohortActor extends AbstractUntypedActor {
 
     private class PostPreCommit extends CohortStateWithStep<Commit, PostPreCommitStep> {
 
-        PostPreCommit(String txId, PostPreCommitStep step) {
+        PostPreCommit(TransactionIdentifier txId, PostPreCommitStep step) {
             super(txId, step);
         }
 
         @Override
+        @SuppressWarnings("checkstyle:IllegalCatch")
         CohortBehaviour<?> process(Commit message) {
             try {
                 getStep().commit().get();
@@ -268,7 +273,7 @@ final class DataTreeCohortActor extends AbstractUntypedActor {
 
     }
 
-    static Props props(final DOMDataTreeCommitCohort cohort) {
-        return Props.create(DataTreeCohortActor.class, cohort);
+    static Props props(final DOMDataTreeCommitCohort cohort, final YangInstanceIdentifier registeredPath) {
+        return Props.create(DataTreeCohortActor.class, cohort, registeredPath);
     }
 }