Class ImmutableElectionTerm
- java.lang.Object
-
- org.opendaylight.controller.cluster.raft.ImmutableElectionTerm
-
- All Implemented Interfaces:
ElectionTerm
public final class ImmutableElectionTerm extends Object implements ElectionTerm
Immutable implementation of ElectionTerm.- Author:
- Thomas Pantelis
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ElectionTermcopyOf(ElectionTerm from)longgetCurrentTerm()Returns the current leader's Raft term.StringgetVotedFor()Returns the id of the candidate that this server voted for in current term.StringtoString()voidupdate(long newTerm, String newVotedFor)This method updates the in-memory election term state.voidupdateAndPersist(long newTerm, String newVotedFor)This method updates the in-memory election term state and persists it so it can be recovered on next restart.
-
-
-
Method Detail
-
getCurrentTerm
public long getCurrentTerm()
Description copied from interface:ElectionTermReturns the current leader's Raft term.- Specified by:
getCurrentTermin interfaceElectionTerm- Returns:
- the current leader's Raft term.
-
getVotedFor
public String getVotedFor()
Description copied from interface:ElectionTermReturns the id of the candidate that this server voted for in current term.- Specified by:
getVotedForin interfaceElectionTerm- Returns:
- candidate id that received the vote or null if no candidate was voted for.
-
update
public void update(long newTerm, String newVotedFor)Description copied from interface:ElectionTermThis method updates the in-memory election term state. This method should be called when recovering election state from persistent storage.- Specified by:
updatein interfaceElectionTerm- Parameters:
newTerm- the election term.newVotedFor- the candidate id that was voted for.
-
updateAndPersist
public void updateAndPersist(long newTerm, String newVotedFor)Description copied from interface:ElectionTermThis method updates the in-memory election term state and persists it so it can be recovered on next restart. This method should be called when starting a new election or when a Raft RPC message is received with a higher term.- Specified by:
updateAndPersistin interfaceElectionTerm- Parameters:
newTerm- the election term.newVotedFor- the candidate id that was voted for.
-
copyOf
public static ElectionTerm copyOf(ElectionTerm from)
-
-