a10c6ac3fb1b6d673a9f8e5b3517e72cebdde9f5
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / BatchedModificationsReply.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 java.io.IOException;
11 import java.io.ObjectInput;
12 import java.io.ObjectOutput;
13
14 /**
15  * The reply for the BatchedModifications message.
16  *
17  * @author Thomas Pantelis
18  */
19 public class BatchedModificationsReply extends VersionedExternalizableMessage {
20     private static final long serialVersionUID = 1L;
21
22     private static final byte COHORT_PATH_NOT_PRESENT = 0;
23     private static final byte COHORT_PATH_PRESENT = 1;
24
25     private int numBatched;
26     private String cohortPath;
27
28     public BatchedModificationsReply() {
29     }
30
31     public BatchedModificationsReply(int numBatched) {
32         this.numBatched = numBatched;
33     }
34
35     public BatchedModificationsReply(int numBatched, String cohortPath) {
36         this.numBatched = numBatched;
37         this.cohortPath = cohortPath;
38     }
39
40     public int getNumBatched() {
41         return numBatched;
42     }
43
44     public String getCohortPath() {
45         return cohortPath;
46     }
47
48     @Override
49     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
50         super.readExternal(in);
51         numBatched = in.readInt();
52
53         if(in.readByte() == COHORT_PATH_PRESENT) {
54             cohortPath = in.readUTF();
55         }
56     }
57
58     @Override
59     public void writeExternal(ObjectOutput out) throws IOException {
60         super.writeExternal(out);
61         out.writeInt(numBatched);
62
63         if(cohortPath != null) {
64             out.writeByte(COHORT_PATH_PRESENT);
65             out.writeUTF(cohortPath);
66         } else {
67             out.writeByte(COHORT_PATH_NOT_PRESENT);
68         }
69     }
70
71     @Override
72     public Object toSerializable() {
73         return this;
74     }
75
76     @Override
77     public String toString() {
78         StringBuilder builder = new StringBuilder();
79         builder.append("BatchedModificationsReply [numBatched=").append(numBatched).append(", cohortPath=")
80                 .append(cohortPath).append("]");
81         return builder.toString();
82     }
83 }