Elide front-end 3PC for single-shard Tx
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / BatchedModifications.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.datastore.messages;
9
10 import com.google.common.base.Preconditions;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification;
15
16 /**
17  * Message used to batch write, merge, delete modification operations to the  ShardTransaction actor.
18  *
19  * @author Thomas Pantelis
20  */
21 public class BatchedModifications extends MutableCompositeModification implements SerializableMessage {
22     private static final long serialVersionUID = 1L;
23
24     private boolean ready;
25     private boolean doCommitOnReady;
26     private int totalMessagesSent;
27     private String transactionID;
28     private String transactionChainID;
29
30     public BatchedModifications() {
31     }
32
33     public BatchedModifications(String transactionID, short version, String transactionChainID) {
34         super(version);
35         this.transactionID = Preconditions.checkNotNull(transactionID, "transactionID can't be null");
36         this.transactionChainID = transactionChainID != null ? transactionChainID : "";
37     }
38
39     public boolean isReady() {
40         return ready;
41     }
42
43     public void setReady(boolean ready) {
44         this.ready = ready;
45     }
46
47     public boolean isDoCommitOnReady() {
48         return doCommitOnReady;
49     }
50
51     public void setDoCommitOnReady(boolean doCommitOnReady) {
52         this.doCommitOnReady = doCommitOnReady;
53     }
54
55     public int getTotalMessagesSent() {
56         return totalMessagesSent;
57     }
58
59     public void setTotalMessagesSent(int totalMessagesSent) {
60         this.totalMessagesSent = totalMessagesSent;
61     }
62
63     public String getTransactionID() {
64         return transactionID;
65     }
66
67     public String getTransactionChainID() {
68         return transactionChainID;
69     }
70
71     @Override
72     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
73         super.readExternal(in);
74         transactionID = in.readUTF();
75         transactionChainID = in.readUTF();
76         ready = in.readBoolean();
77         totalMessagesSent = in.readInt();
78         doCommitOnReady = in.readBoolean();
79     }
80
81     @Override
82     public void writeExternal(ObjectOutput out) throws IOException {
83         super.writeExternal(out);
84         out.writeUTF(transactionID);
85         out.writeUTF(transactionChainID);
86         out.writeBoolean(ready);
87         out.writeInt(totalMessagesSent);
88         out.writeBoolean(doCommitOnReady);
89     }
90
91     @Override
92     public Object toSerializable() {
93         return this;
94     }
95
96     @Override
97     public String toString() {
98         StringBuilder builder = new StringBuilder();
99         builder.append("BatchedModifications [transactionID=").append(transactionID).append(", transactionChainID=")
100                 .append(transactionChainID).append(", ready=").append(ready).append(", totalMessagesSent=")
101                 .append(totalMessagesSent).append(", modifications size=").append(getModifications().size())
102                 .append("]");
103         return builder.toString();
104     }
105 }