import akka.actor.Props;
import akka.actor.Status;
import com.google.common.base.Preconditions;
+import java.util.Collection;
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.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
protected void handleReceive(final Object message) {
+ LOG.debug("handleReceive for cohort {} - currentState: {}, message: {}", cohort.getClass().getName(),
+ currentState, message);
+
currentState = currentState.handle(message);
}
*
* @param <R> Reply message type
*/
- static abstract class CommitProtocolCommand<R extends CommitReply> {
+ abstract static class CommitProtocolCommand<R extends CommitReply> {
private final TransactionIdentifier txId;
protected CommitProtocolCommand(TransactionIdentifier txId) {
this.txId = Preconditions.checkNotNull(txId);
}
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + " [txId=" + txId + "]";
+ }
}
static final class CanCommit extends CommitProtocolCommand<Success> {
- private final DOMDataTreeCandidate candidate;
+ private final Collection<DOMDataTreeCandidate> candidates;
private final ActorRef cohort;
private final SchemaContext schema;
- CanCommit(TransactionIdentifier txId, DOMDataTreeCandidate candidate, SchemaContext schema, ActorRef cohort) {
+ CanCommit(TransactionIdentifier txId, Collection<DOMDataTreeCandidate> candidates, SchemaContext schema,
+ ActorRef cohort) {
super(txId);
this.cohort = Preconditions.checkNotNull(cohort);
- this.candidate = Preconditions.checkNotNull(candidate);
+ this.candidates = Preconditions.checkNotNull(candidates);
this.schema = Preconditions.checkNotNull(schema);
}
- DOMDataTreeCandidate getCandidate() {
- return candidate;
+ Collection<DOMDataTreeCandidate> getCandidates() {
+ return candidates;
}
SchemaContext getSchema() {
return cohort;
}
+ @Override
+ public String toString() {
+ return "CanCommit [txId=" + getTxId() + ", candidates=" + candidates + ", cohort=" + cohort + "]";
+ }
}
- static abstract class CommitReply {
+ abstract static class CommitReply {
private final ActorRef cohortRef;
private final TransactionIdentifier txId;
final TransactionIdentifier getTxId() {
return txId;
}
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + " [txId=" + txId + ", cohortRef=" + cohortRef + "]";
+ }
}
static final class Success extends CommitReply {
- public Success(ActorRef cohortRef, TransactionIdentifier txId) {
+ Success(ActorRef cohortRef, TransactionIdentifier txId) {
super(cohortRef, txId);
}
-
}
static final class PreCommit extends CommitProtocolCommand<Success> {
- public PreCommit(TransactionIdentifier txId) {
+ PreCommit(TransactionIdentifier txId) {
super(txId);
}
}
static final class Abort extends CommitProtocolCommand<Success> {
- public Abort(TransactionIdentifier txId) {
+ Abort(TransactionIdentifier txId) {
super(txId);
}
}
static final class Commit extends CommitProtocolCommand<Success> {
- public Commit(TransactionIdentifier txId) {
+ Commit(TransactionIdentifier txId) {
super(txId);
}
}
- private static abstract class CohortBehaviour<E> {
+ private abstract static class CohortBehaviour<E> {
abstract Class<E> getHandledMessageType();
} 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();
abstract CohortBehaviour<?> process(E message);
+ @Override
+ public String toString() {
+ return getClass().getSimpleName();
+ }
}
private class Idle extends CohortBehaviour<CanCommit> {
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
CohortBehaviour<?> process(CanCommit message) {
final PostCanCommitStep nextStep;
try {
- nextStep = cohort.canCommit(message.getTxId(), message.getCandidate(), message.getSchema()).get();
+ nextStep = cohort.canCommit(message.getTxId(), message.getCandidates(), message.getSchema()).get();
} catch (final Exception e) {
getSender().tell(new Status.Failure(e), getSelf());
return this;
CohortBehaviour<?> abort() {
return this;
}
-
}
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
final CohortBehaviour<?> abort() {
try {
getStep().abort().get();
return idleState;
}
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + " [txId=" + txId + ", step=" + step + "]";
+ }
}
private class PostCanCommit extends CohortStateWithStep<PreCommit, PostCanCommitStep> {
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
CohortBehaviour<?> process(PreCommit message) {
final PostPreCommitStep nextStep;
try {
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
CohortBehaviour<?> process(Commit message) {
try {
getStep().commit().get();
}
- 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);
}
}