ff79004bcebdcaea3ff541951c3a5a170e5e74ce
[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 import javax.annotation.Nullable;
12
13 /**
14  * ElectionTerm contains information about a RaftActors election term.
15  * <p>
16  * This information includes the last known current term of the RaftActor
17  * and which candidate was voted for by the RaftActor in that term.
18  * <p>
19  * This class ensures that election term information is persisted.
20  */
21 public interface ElectionTerm {
22     /**
23      * Returns the current leader's Raft term.
24      *
25      * @return the current leader's Raft term.
26      */
27     long getCurrentTerm();
28
29     /**
30      * Returns the id of the candidate that this server voted for in current term.
31      *
32      * @return candidate id that received the vote or null if no candidate was voted for.
33      */
34     @Nullable
35     String getVotedFor();
36
37     /**
38      * This method updates the in-memory election term state. This method should be called when recovering election
39      * state from persistent storage.
40      *
41      * @param term the election term.
42      * @param votedFor the candidate id that was voted for.
43      */
44     void update(long term, @Nullable String votedFor);
45
46     /**
47      * This method updates the in-memory election term state and persists it so it can be recovered on next restart.
48      * This method should be called when starting a new election or when a Raft RPC message is received  with a higher
49      * term.
50      *
51      * @param term the election term.
52      * @param votedFor the candidate id that was voted for.
53      */
54     void updateAndPersist(long term, @Nullable String votedFor);
55 }