2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.datastore.messages;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.Preconditions;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import java.util.Optional;
17 import java.util.SortedSet;
18 import java.util.TreeSet;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
21 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
22 import org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification;
25 * Message used to batch write, merge, delete modification operations to the ShardTransaction actor.
27 * @author Thomas Pantelis
29 @Deprecated(since = "9.0.0", forRemoval = true)
30 public final class BatchedModifications extends MutableCompositeModification {
32 private static final long serialVersionUID = 1L;
34 private boolean ready;
35 private boolean doCommitOnReady;
36 private int totalMessagesSent;
37 private TransactionIdentifier transactionId;
39 private @Nullable SortedSet<String> participatingShardNames;
41 public BatchedModifications() {
44 public BatchedModifications(final TransactionIdentifier transactionId, final short version) {
46 this.transactionId = requireNonNull(transactionId, "transactionID can't be null");
49 public boolean isReady() {
53 public void setReady(final Optional<SortedSet<String>> possibleParticipatingShardNames) {
55 participatingShardNames = requireNonNull(possibleParticipatingShardNames).orElse(null);
56 Preconditions.checkArgument(participatingShardNames == null || participatingShardNames.size() > 1);
59 public void setReady() {
60 setReady(Optional.empty());
63 public Optional<SortedSet<String>> getParticipatingShardNames() {
64 return Optional.ofNullable(participatingShardNames);
67 public boolean isDoCommitOnReady() {
68 return doCommitOnReady;
71 public void setDoCommitOnReady(final boolean doCommitOnReady) {
72 this.doCommitOnReady = doCommitOnReady;
75 public int getTotalMessagesSent() {
76 return totalMessagesSent;
79 public void setTotalMessagesSent(final int totalMessagesSent) {
80 this.totalMessagesSent = totalMessagesSent;
83 public TransactionIdentifier getTransactionId() {
88 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
89 super.readExternal(in);
90 transactionId = TransactionIdentifier.readFrom(in);
91 ready = in.readBoolean();
92 totalMessagesSent = in.readInt();
93 doCommitOnReady = in.readBoolean();
95 if (getVersion() >= DataStoreVersions.FLUORINE_VERSION) {
96 final int count = in.readInt();
98 SortedSet<String> shardNames = new TreeSet<>();
99 for (int i = 0; i < count; i++) {
100 shardNames.add((String) in.readObject());
103 participatingShardNames = shardNames;
109 public void writeExternal(final ObjectOutput out) throws IOException {
110 super.writeExternal(out);
111 transactionId.writeTo(out);
112 out.writeBoolean(ready);
113 out.writeInt(totalMessagesSent);
114 out.writeBoolean(doCommitOnReady);
116 if (getVersion() >= DataStoreVersions.FLUORINE_VERSION) {
117 if (participatingShardNames != null) {
118 out.writeInt(participatingShardNames.size());
119 for (String shardName : participatingShardNames) {
120 out.writeObject(shardName);
129 public String toString() {
130 return "BatchedModifications [transactionId=" + transactionId
131 + ", ready=" + isReady()
132 + ", participatingShardNames=" + participatingShardNames
133 + ", totalMessagesSent=" + totalMessagesSent
134 + ", modifications size=" + getModifications().size() + "]";