c0e89a8ef41a6c5ecaf2282eb8d4a131d43876c6
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / messages / AppendEntries.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.ReplicatedLogEntry;
12
13 import java.util.List;
14
15 /**
16  * Invoked by leader to replicate log entries (§5.3); also used as
17  * heartbeat (§5.2).
18  */
19 public class AppendEntries extends AbstractRaftRPC {
20     // So that follower can redirect clients
21     private final String leaderId;
22
23     // Index of log entry immediately preceding new ones
24     private final long prevLogIndex;
25
26     // term of prevLogIndex entry
27     private final long prevLogTerm;
28
29     // log entries to store (empty for heartbeat;
30     // may send more than one for efficiency)
31     private final List<ReplicatedLogEntry> entries;
32
33     // leader's commitIndex
34     private final long leaderCommit;
35
36     public AppendEntries(long term, String leaderId, long prevLogIndex,
37         long prevLogTerm, List<ReplicatedLogEntry> entries, long leaderCommit) {
38         super(term);
39         this.leaderId = leaderId;
40         this.prevLogIndex = prevLogIndex;
41         this.prevLogTerm = prevLogTerm;
42         this.entries = entries;
43         this.leaderCommit = leaderCommit;
44     }
45
46     public String getLeaderId() {
47         return leaderId;
48     }
49
50     public long getPrevLogIndex() {
51         return prevLogIndex;
52     }
53
54     public long getPrevLogTerm() {
55         return prevLogTerm;
56     }
57
58     public List<ReplicatedLogEntry> getEntries() {
59         return entries;
60     }
61
62     public long getLeaderCommit() {
63         return leaderCommit;
64     }
65 }