*/
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;
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;
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
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
}
checkState(State.READY);
- this.callback = Preconditions.checkNotNull(newCallback);
+ this.callback = requireNonNull(newCallback);
state = State.CAN_COMMIT_PENDING;
if (nextFailure == null) {
@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) {
@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) {
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);
}