Reduce JSR305 proliferation
[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 package org.opendaylight.controller.cluster.raft;
9
10 import org.eclipse.jdt.annotation.Nullable;
11
12 /**
13  * ElectionTerm contains information about a RaftActors election term.
14  *
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  *
19  * <p>
20  * This class ensures that election term information is persisted.
21  */
22 public interface ElectionTerm {
23     /**
24      * Returns the current leader's Raft term.
25      *
26      * @return the current leader's Raft term.
27      */
28     long getCurrentTerm();
29
30     /**
31      * Returns the id of the candidate that this server voted for in current term.
32      *
33      * @return candidate id that received the vote or null if no candidate was voted for.
34      */
35     @Nullable 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 }