*/
package org.opendaylight.controller.cluster.datastore.messages;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.base.Preconditions;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+import java.util.Optional;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import javax.annotation.Nullable;
import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
+import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
import org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification;
/**
private boolean ready;
private boolean doCommitOnReady;
private int totalMessagesSent;
- private TransactionIdentifier transactionID;
+ private TransactionIdentifier transactionId;
+ @Nullable
+ private SortedSet<String> participatingShardNames;
public BatchedModifications() {
}
- public BatchedModifications(TransactionIdentifier transactionID, short version) {
+ public BatchedModifications(TransactionIdentifier transactionId, short version) {
super(version);
- this.transactionID = Preconditions.checkNotNull(transactionID, "transactionID can't be null");
+ this.transactionId = requireNonNull(transactionId, "transactionID can't be null");
}
public boolean isReady() {
return ready;
}
- public void setReady(boolean ready) {
- this.ready = ready;
+ public void setReady(Optional<SortedSet<String>> possibleParticipatingShardNames) {
+ this.ready = true;
+ this.participatingShardNames = requireNonNull(possibleParticipatingShardNames).orElse(null);
+ Preconditions.checkArgument(this.participatingShardNames == null || this.participatingShardNames.size() > 1);
+ }
+
+ public void setReady() {
+ setReady(Optional.empty());
+ }
+
+ public Optional<SortedSet<String>> getParticipatingShardNames() {
+ return Optional.ofNullable(participatingShardNames);
}
public boolean isDoCommitOnReady() {
this.totalMessagesSent = totalMessagesSent;
}
- public TransactionIdentifier getTransactionID() {
- return transactionID;
+ public TransactionIdentifier getTransactionId() {
+ return transactionId;
}
-
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
super.readExternal(in);
- transactionID = TransactionIdentifier.readFrom(in);
+ transactionId = TransactionIdentifier.readFrom(in);
ready = in.readBoolean();
totalMessagesSent = in.readInt();
doCommitOnReady = in.readBoolean();
+
+ if (getVersion() >= DataStoreVersions.FLUORINE_VERSION) {
+ final int count = in.readInt();
+ if (count != 0) {
+ SortedSet<String> shardNames = new TreeSet<>();
+ for (int i = 0; i < count; i++) {
+ shardNames.add((String) in.readObject());
+ }
+
+ participatingShardNames = shardNames;
+ }
+ }
}
@Override
public void writeExternal(ObjectOutput out) throws IOException {
super.writeExternal(out);
- transactionID.writeTo(out);
+ transactionId.writeTo(out);
out.writeBoolean(ready);
out.writeInt(totalMessagesSent);
out.writeBoolean(doCommitOnReady);
+
+ if (getVersion() >= DataStoreVersions.FLUORINE_VERSION) {
+ if (participatingShardNames != null) {
+ out.writeInt(participatingShardNames.size());
+ for (String shardName: participatingShardNames) {
+ out.writeObject(shardName);
+ }
+ } else {
+ out.writeInt(0);
+ }
+ }
}
@Override
public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("BatchedModifications [transactionID=").append(transactionID).append(", ready=").append(ready)
- .append(", totalMessagesSent=").append(totalMessagesSent).append(", modifications size=")
- .append(getModifications().size()).append("]");
- return builder.toString();
+ return "BatchedModifications [transactionId=" + transactionId
+ + ", ready=" + isReady()
+ + ", participatingShardNames=" + participatingShardNames
+ + ", totalMessagesSent=" + totalMessagesSent
+ + ", modifications size=" + getModifications().size() + "]";
}
}