Initial code/design for an Akka Raft implementation
[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 java.util.List;
12
13 /**
14  * Invoked by leader to replicate log entries (§5.3); also used as
15  * heartbeat (§5.2).
16  */
17 public class AppendEntries {
18     // Leaders term
19     private final long term;
20
21     // So that follower can redirect clients
22     private final String leaderId;
23
24     // Index of log entry immediately preceding new ones
25     private final long prevLogIndex;
26
27     // term of prevLogIndex entry
28     private final long prevLogTerm;
29
30     // log entries to store (empty for heartbeat;
31     // may send more than one for efficiency)
32     private final List<Object> entries;
33
34     public AppendEntries(long term, String leaderId, long prevLogIndex,
35         long prevLogTerm, List<Object> entries) {
36         this.term = term;
37         this.leaderId = leaderId;
38         this.prevLogIndex = prevLogIndex;
39         this.prevLogTerm = prevLogTerm;
40         this.entries = entries;
41     }
42
43     public long getTerm() {
44         return term;
45     }
46
47     public String getLeaderId() {
48         return leaderId;
49     }
50
51     public long getPrevLogIndex() {
52         return prevLogIndex;
53     }
54
55     public long getPrevLogTerm() {
56         return prevLogTerm;
57     }
58
59     public List<Object> getEntries() {
60         return entries;
61     }
62 }