ffdfaa6a0ed112ce50eb22d881d2731dd7a69978
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / messages / AppendEntriesReply.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 org.opendaylight.controller.cluster.raft.RaftVersions;
12
13 /**
14  * Reply for the AppendEntriesRpc message
15  */
16 public class AppendEntriesReply extends AbstractRaftRPC {
17     private static final long serialVersionUID = -7487547356392536683L;
18
19     // true if follower contained entry matching
20     // prevLogIndex and prevLogTerm
21     private final boolean success;
22
23     // The index of the last entry in the followers log
24     // This will be used to set the matchIndex for the follower on the
25     // Leader
26     private final long logLastIndex;
27
28     private final long logLastTerm;
29
30     // The followerId - this will be used to figure out which follower is
31     // responding
32     private final String followerId;
33
34     private final short payloadVersion;
35
36     private final short raftVersion = RaftVersions.CURRENT_VERSION;
37
38     private final boolean forceInstallSnapshot;
39
40     public AppendEntriesReply(String followerId, long term, boolean success, long logLastIndex, long logLastTerm,
41             short payloadVersion) {
42         this(followerId, term, success, logLastIndex, logLastTerm, payloadVersion, false);
43     }
44
45     public AppendEntriesReply(String followerId, long term, boolean success, long logLastIndex, long logLastTerm,
46                               short payloadVersion, boolean forceInstallSnapshot) {
47         super(term);
48
49         this.followerId = followerId;
50         this.success = success;
51         this.logLastIndex = logLastIndex;
52         this.logLastTerm = logLastTerm;
53         this.payloadVersion = payloadVersion;
54         this.forceInstallSnapshot = forceInstallSnapshot;
55     }
56
57     public boolean isSuccess() {
58         return success;
59     }
60
61     public long getLogLastIndex() {
62         return logLastIndex;
63     }
64
65     public long getLogLastTerm() {
66         return logLastTerm;
67     }
68
69     public String getFollowerId() {
70         return followerId;
71     }
72
73     public short getPayloadVersion() {
74         return payloadVersion;
75     }
76
77     public short getRaftVersion() {
78         return raftVersion;
79     }
80
81     public boolean isForceInstallSnapshot() {
82         return forceInstallSnapshot;
83     }
84
85     @Override
86     public String toString() {
87         return "AppendEntriesReply [term=" + getTerm() + ", success=" + success + ", followerId=" + followerId
88                 + ", logLastIndex=" + logLastIndex + ", logLastTerm=" + logLastTerm + ", forceInstallSnapshot="
89                 + forceInstallSnapshot + ", payloadVersion=" + payloadVersion + ", raftVersion=" + raftVersion + "]";
90     }
91 }