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 ElectionTerm
copyOf(ElectionTerm from)
long
getCurrentTerm()
Returns the current leader's Raft term.String
getVotedFor()
Returns the id of the candidate that this server voted for in current term.String
toString()
void
update(long newTerm, String newVotedFor)
This method updates the in-memory election term state.void
updateAndPersist(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:ElectionTerm
Returns the current leader's Raft term.- Specified by:
getCurrentTerm
in interfaceElectionTerm
- Returns:
- the current leader's Raft term.
-
getVotedFor
public String getVotedFor()
Description copied from interface:ElectionTerm
Returns the id of the candidate that this server voted for in current term.- Specified by:
getVotedFor
in 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:ElectionTerm
This method updates the in-memory election term state. This method should be called when recovering election state from persistent storage.- Specified by:
update
in 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:ElectionTerm
This 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:
updateAndPersist
in interfaceElectionTerm
- Parameters:
newTerm
- the election term.newVotedFor
- the candidate id that was voted for.
-
copyOf
public static ElectionTerm copyOf(ElectionTerm from)
-
-