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