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