String performance and maintenability
[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.access.concepts.TransactionIdentifier;
15 import org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification;
16
17 /**
18  * Message used to batch write, merge, delete modification operations to the  ShardTransaction actor.
19  *
20  * @author Thomas Pantelis
21  */
22 public class BatchedModifications extends MutableCompositeModification {
23     private static final long serialVersionUID = 1L;
24
25     private boolean ready;
26     private boolean doCommitOnReady;
27     private int totalMessagesSent;
28     private TransactionIdentifier transactionId;
29
30     public BatchedModifications() {
31     }
32
33     public BatchedModifications(TransactionIdentifier transactionId, short version) {
34         super(version);
35         this.transactionId = Preconditions.checkNotNull(transactionId, "transactionID can't be null");
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 boolean isDoCommitOnReady() {
47         return doCommitOnReady;
48     }
49
50     public void setDoCommitOnReady(boolean doCommitOnReady) {
51         this.doCommitOnReady = doCommitOnReady;
52     }
53
54     public int getTotalMessagesSent() {
55         return totalMessagesSent;
56     }
57
58     public void setTotalMessagesSent(int totalMessagesSent) {
59         this.totalMessagesSent = totalMessagesSent;
60     }
61
62     public TransactionIdentifier getTransactionId() {
63         return transactionId;
64     }
65
66
67     @Override
68     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
69         super.readExternal(in);
70         transactionId = TransactionIdentifier.readFrom(in);
71         ready = in.readBoolean();
72         totalMessagesSent = in.readInt();
73         doCommitOnReady = in.readBoolean();
74     }
75
76     @Override
77     public void writeExternal(ObjectOutput out) throws IOException {
78         super.writeExternal(out);
79         transactionId.writeTo(out);
80         out.writeBoolean(ready);
81         out.writeInt(totalMessagesSent);
82         out.writeBoolean(doCommitOnReady);
83     }
84
85     @Override
86     public String toString() {
87         return "BatchedModifications [transactionId=" + transactionId
88                 + ", ready=" + ready
89                 + ", totalMessagesSent=" + totalMessagesSent
90                 + ", modifications size=" + getModifications().size() + "]";
91     }
92 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.