X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FSimpleShardDataTreeCohort.java;h=f42af0b88e5847c3201520cfbca632b4b2da4dcd;hp=b5b49c2396c772a0fbfdd75e4bcc1ff8e14ca1cb;hb=HEAD;hpb=731e7284cf0895fdb1b89427f91762e80e67c2ff diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohort.java index b5b49c2396..2c7d13189f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohort.java @@ -7,21 +7,23 @@ */ package org.opendaylight.controller.cluster.datastore; +import static com.google.common.base.Verify.verifyNotNull; 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 javax.annotation.Nullable; +import org.eclipse.jdt.annotation.NonNull; +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; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; +import org.opendaylight.yangtools.yang.common.Empty; +import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate; +import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateTip; +import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,10 +32,9 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { private final DataTreeModification transaction; private final ShardDataTree dataTree; - private final TransactionIdentifier transactionId; + private final @NonNull TransactionIdentifier transactionId; private final CompositeDataTreeCohort userCohorts; - @Nullable - private final SortedSet participatingShardNames; + private final @Nullable SortedSet participatingShardNames; private State state = State.READY; private DataTreeCandidateTip candidate; @@ -55,13 +56,13 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { this.dataTree = requireNonNull(dataTree); this.transaction = requireNonNull(transaction); this.transactionId = requireNonNull(transactionId); - this.userCohorts = null; - this.participatingShardNames = null; + userCohorts = null; + participatingShardNames = null; this.nextFailure = requireNonNull(nextFailure); } @Override - public TransactionIdentifier getIdentifier() { + TransactionIdentifier transactionId() { return transactionId; } @@ -82,17 +83,17 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { private void checkState(final State expected) { Preconditions.checkState(state == expected, "State %s does not match expected state %s for %s", - state, expected, getIdentifier()); + state, expected, transactionId()); } @Override - public void canCommit(final FutureCallback newCallback) { + public void canCommit(final FutureCallback newCallback) { if (state == State.CAN_COMMIT_PENDING) { return; } checkState(State.READY); - this.callback = requireNonNull(newCallback); + callback = requireNonNull(newCallback); state = State.CAN_COMMIT_PENDING; if (nextFailure == null) { @@ -105,7 +106,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { @Override public void preCommit(final FutureCallback newCallback) { checkState(State.CAN_COMMIT_COMPLETE); - this.callback = requireNonNull(newCallback); + callback = requireNonNull(newCallback); state = State.PRE_COMMIT_PENDING; if (nextFailure == null) { @@ -116,9 +117,9 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { } @Override - public void abort(final FutureCallback abortCallback) { + public void abort(final FutureCallback abortCallback) { if (!dataTree.startAbort(this)) { - abortCallback.onSuccess(null); + abortCallback.onSuccess(Empty.value()); return; } @@ -127,15 +128,15 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { final Optional> maybeAborts = userCohorts.abort(); if (!maybeAborts.isPresent()) { - abortCallback.onSuccess(null); + abortCallback.onSuccess(Empty.value()); return; } - maybeAborts.get().whenComplete((noop, failure) -> { + maybeAborts.orElseThrow().whenComplete((noop, failure) -> { if (failure != null) { abortCallback.onFailure(failure); } else { - abortCallback.onSuccess(null); + abortCallback.onSuccess(Empty.value()); } }); } @@ -143,7 +144,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { @Override public void commit(final FutureCallback newCallback) { checkState(State.PRE_COMMIT_COMPLETE); - this.callback = requireNonNull(newCallback); + callback = requireNonNull(newCallback); state = State.COMMIT_PENDING; if (nextFailure == null) { @@ -155,20 +156,20 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { private FutureCallback switchState(final State newState) { @SuppressWarnings("unchecked") - final FutureCallback ret = (FutureCallback) this.callback; - this.callback = null; + final FutureCallback ret = (FutureCallback) callback; + callback = null; LOG.debug("Transaction {} changing state from {} to {}", transactionId, state, newState); - this.state = newState; + state = newState; return ret; } void setNewCandidate(final DataTreeCandidateTip dataTreeCandidate) { checkState(State.PRE_COMMIT_COMPLETE); - this.candidate = Verify.verifyNotNull(dataTreeCandidate); + candidate = verifyNotNull(dataTreeCandidate); } void successfulCanCommit() { - switchState(State.CAN_COMMIT_COMPLETE).onSuccess(null); + switchState(State.CAN_COMMIT_COMPLETE).onSuccess(Empty.value()); } void failedCanCommit(final Exception cause) { @@ -182,16 +183,16 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { * @param dataTreeCandidate {@link DataTreeCandidate} under consideration * @param futureCallback the callback to invoke on completion, which may be immediate or async. */ - void userPreCommit(final DataTreeCandidate dataTreeCandidate, final FutureCallback futureCallback) { + void userPreCommit(final DataTreeCandidate dataTreeCandidate, final FutureCallback futureCallback) { userCohorts.reset(); - final Optional> maybeCanCommitFuture = userCohorts.canCommit(dataTreeCandidate); + final Optional> maybeCanCommitFuture = userCohorts.canCommit(dataTreeCandidate); if (!maybeCanCommitFuture.isPresent()) { doUserPreCommit(futureCallback); return; } - maybeCanCommitFuture.get().whenComplete((noop, failure) -> { + maybeCanCommitFuture.orElseThrow().whenComplete((noop, failure) -> { if (failure != null) { futureCallback.onFailure(failure); } else { @@ -200,25 +201,25 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { }); } - private void doUserPreCommit(final FutureCallback futureCallback) { - final Optional> maybePreCommitFuture = userCohorts.preCommit(); + private void doUserPreCommit(final FutureCallback futureCallback) { + final Optional> maybePreCommitFuture = userCohorts.preCommit(); if (!maybePreCommitFuture.isPresent()) { - futureCallback.onSuccess(null); + futureCallback.onSuccess(Empty.value()); return; } - maybePreCommitFuture.get().whenComplete((noop, failure) -> { + maybePreCommitFuture.orElseThrow().whenComplete((noop, failure) -> { if (failure != null) { futureCallback.onFailure(failure); } else { - futureCallback.onSuccess(null); + futureCallback.onSuccess(Empty.value()); } }); } void successfulPreCommit(final DataTreeCandidateTip dataTreeCandidate) { LOG.trace("Transaction {} prepared candidate {}", transaction, dataTreeCandidate); - this.candidate = Verify.verifyNotNull(dataTreeCandidate); + candidate = verifyNotNull(dataTreeCandidate); switchState(State.PRE_COMMIT_COMPLETE).onSuccess(dataTreeCandidate); } @@ -234,13 +235,13 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { } void successfulCommit(final UnsignedLong journalIndex, final Runnable onComplete) { - final Optional> maybeCommitFuture = userCohorts.commit(); + final Optional> maybeCommitFuture = userCohorts.commit(); if (!maybeCommitFuture.isPresent()) { finishSuccessfulCommit(journalIndex, onComplete); return; } - maybeCommitFuture.get().whenComplete((noop, failure) -> { + maybeCommitFuture.orElseThrow().whenComplete((noop, failure) -> { if (failure != null) { LOG.error("User cohorts failed to commit", failure); } @@ -272,7 +273,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { void reportFailure(final Exception cause) { if (nextFailure == null) { - this.nextFailure = requireNonNull(cause); + nextFailure = requireNonNull(cause); } else { LOG.debug("Transaction {} already has a set failure, not updating it", transactionId, cause); }