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