BUG 2817 - Basic implementation of RemoveServer in the Raft code
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / ElectionTerm.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;
10
11 /**
12  * ElectionTerm contains information about a RaftActors election term.
13  * <p>
14  * This information includes the last known current term of the RaftActor
15  * and which peer was voted for by the RaftActor in that term
16  * <p>
17  * This class ensures that election term information is persisted
18  */
19 public interface ElectionTerm {
20     /**
21      * latest term server has seen (initialized to 0
22      * on first boot, increases monotonically)
23      */
24     long getCurrentTerm();
25
26     /**
27      * candidateId that received vote in current
28      * term (or null if none)
29      */
30     String getVotedFor();
31
32     /**
33      * To be called mainly when we are recovering in-memory election state from
34      * persistent storage
35      *
36      * @param currentTerm
37      * @param votedFor
38      */
39     void update(long currentTerm, String votedFor);
40
41     /**
42      * To be called when we need to update the current term either because we
43      * received a message from someone with a more up-to-date term or because we
44      * just voted for someone
45      * <p>
46      * This information needs to be persisted so that on recovery the replica
47      * can start itself in the right term and know if it has already voted in
48      * that term or not
49      *
50      * @param currentTerm
51      * @param votedFor
52      */
53     void updateAndPersist(long currentTerm, String votedFor);
54 }