Add optional timeout parameter for backup rpc
[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 package org.opendaylight.controller.cluster.raft.messages;
9
10 import java.io.Externalizable;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14
15 public final class InstallSnapshotReply extends AbstractRaftRPC {
16     private static final long serialVersionUID = 642227896390779503L;
17
18     // The followerId - this will be used to figure out which follower is
19     // responding
20     private final String followerId;
21     private final int chunkIndex;
22     private final boolean success;
23
24     public InstallSnapshotReply(final long term, final String followerId, final int chunkIndex, final boolean success) {
25         super(term);
26         this.followerId = followerId;
27         this.chunkIndex = chunkIndex;
28         this.success = success;
29     }
30
31     public String getFollowerId() {
32         return followerId;
33     }
34
35     public int getChunkIndex() {
36         return chunkIndex;
37     }
38
39     public boolean isSuccess() {
40         return success;
41     }
42
43     @Override
44     public String toString() {
45         return "InstallSnapshotReply [term=" + getTerm()
46                 + ", followerId=" + followerId
47                 + ", chunkIndex=" + chunkIndex
48                 + ", success=" + success + "]";
49     }
50
51     @Override
52     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         // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
62         // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
63         @SuppressWarnings("checkstyle:RedundantModifier")
64         public Proxy() {
65         }
66
67         Proxy(final InstallSnapshotReply installSnapshotReply) {
68             this.installSnapshotReply = installSnapshotReply;
69         }
70
71         @Override
72         public void writeExternal(final ObjectOutput out) throws IOException {
73             out.writeLong(installSnapshotReply.getTerm());
74             out.writeObject(installSnapshotReply.followerId);
75             out.writeInt(installSnapshotReply.chunkIndex);
76             out.writeBoolean(installSnapshotReply.success);
77         }
78
79         @Override
80         public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
81             long term = in.readLong();
82             String followerId = (String) in.readObject();
83             int chunkIndex = in.readInt();
84             boolean success = in.readBoolean();
85
86             installSnapshotReply = new InstallSnapshotReply(term, followerId, chunkIndex, success);
87         }
88
89         private Object readResolve() {
90             return installSnapshotReply;
91         }
92     }
93 }