Merge "CDS: Split out TransactionFutureCallback"
[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 int totalMessagesSent;
26     private String transactionID;
27     private String transactionChainID;
28
29     public BatchedModifications() {
30     }
31
32     public BatchedModifications(String transactionID, short version, String transactionChainID) {
33         super(version);
34         this.transactionID = Preconditions.checkNotNull(transactionID, "transactionID can't be null");
35         this.transactionChainID = transactionChainID != null ? transactionChainID : "";
36     }
37
38     public boolean isReady() {
39         return ready;
40     }
41
42     public void setReady(boolean ready) {
43         this.ready = ready;
44     }
45
46     public int getTotalMessagesSent() {
47         return totalMessagesSent;
48     }
49
50     public void setTotalMessagesSent(int totalMessagesSent) {
51         this.totalMessagesSent = totalMessagesSent;
52     }
53
54     public String getTransactionID() {
55         return transactionID;
56     }
57
58     public String getTransactionChainID() {
59         return transactionChainID;
60     }
61
62     @Override
63     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
64         super.readExternal(in);
65         transactionID = in.readUTF();
66         transactionChainID = in.readUTF();
67         ready = in.readBoolean();
68         totalMessagesSent = in.readInt();
69     }
70
71     @Override
72     public void writeExternal(ObjectOutput out) throws IOException {
73         super.writeExternal(out);
74         out.writeUTF(transactionID);
75         out.writeUTF(transactionChainID);
76         out.writeBoolean(ready);
77         out.writeInt(totalMessagesSent);
78     }
79
80     @Override
81     public Object toSerializable() {
82         return this;
83     }
84
85     @Override
86     public String toString() {
87         StringBuilder builder = new StringBuilder();
88         builder.append("BatchedModifications [transactionID=").append(transactionID).append(", transactionChainID=")
89                 .append(transactionChainID).append(", ready=").append(ready).append(", totalMessagesSent=")
90                 .append(totalMessagesSent).append(", modifications size=").append(getModifications().size())
91                 .append("]");
92         return builder.toString();
93     }
94 }