41d2ae68c90e8e2f3846d6c3806693843f2b091c
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / messages / InstallSnapshotReply.java
1 /*
2  * Copyright (c) 2014 Cisco 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
9 package org.opendaylight.controller.cluster.raft.messages;
10
11 import java.io.Externalizable;
12 import java.io.IOException;
13 import java.io.ObjectInput;
14 import java.io.ObjectOutput;
15
16 public class InstallSnapshotReply extends AbstractRaftRPC {
17     private static final long serialVersionUID = 642227896390779503L;
18
19     // The followerId - this will be used to figure out which follower is
20     // responding
21     private final String followerId;
22     private final int chunkIndex;
23     private final boolean success;
24
25     public InstallSnapshotReply(long term, String followerId, int chunkIndex, boolean success) {
26         super(term);
27         this.followerId = followerId;
28         this.chunkIndex = chunkIndex;
29         this.success = success;
30     }
31
32     public String getFollowerId() {
33         return followerId;
34     }
35
36     public int getChunkIndex() {
37         return chunkIndex;
38     }
39
40     public boolean isSuccess() {
41         return success;
42     }
43
44     @Override
45     public String toString() {
46         StringBuilder builder = new StringBuilder();
47         builder.append("InstallSnapshotReply [term=").append(getTerm()).append(", followerId=").append(followerId)
48                 .append(", chunkIndex=").append(chunkIndex).append(", success=").append(success).append("]");
49         return builder.toString();
50     }
51
52     private Object writeReplace() {
53         return new Proxy(this);
54     }
55
56     private static class Proxy implements Externalizable {
57         private static final long serialVersionUID = 1L;
58
59         private InstallSnapshotReply installSnapshotReply;
60
61         public Proxy() {
62         }
63
64         Proxy(InstallSnapshotReply installSnapshotReply) {
65             this.installSnapshotReply = installSnapshotReply;
66         }
67
68         @Override
69         public void writeExternal(ObjectOutput out) throws IOException {
70             out.writeLong(installSnapshotReply.getTerm());
71             out.writeObject(installSnapshotReply.followerId);
72             out.writeInt(installSnapshotReply.chunkIndex);
73             out.writeBoolean(installSnapshotReply.success);
74         }
75
76         @Override
77         public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
78             long term = in.readLong();
79             String followerId = (String) in.readObject();
80             int chunkIndex = in.readInt();
81             boolean success = in.readBoolean();
82
83             installSnapshotReply = new InstallSnapshotReply(term, followerId, chunkIndex, success);
84         }
85
86         private Object readResolve() {
87             return installSnapshotReply;
88         }
89     }
90 }