2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.cluster.raft;
11 import javax.annotation.Nullable;
14 * ElectionTerm contains information about a RaftActors election term.
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.
19 * This class ensures that election term information is persisted.
21 public interface ElectionTerm {
23 * Returns the current leader's Raft term.
25 * @return the current leader's Raft term.
27 long getCurrentTerm();
30 * Returns the id of the candidate that this server voted for in current term.
32 * @return candidate id that received the vote or null if no candidate was voted for.
38 * This method updates the in-memory election term state. This method should be called when recovering election
39 * state from persistent storage.
41 * @param term the election term.
42 * @param votedFor the candidate id that was voted for.
44 void update(long term, @Nullable String votedFor);
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
51 * @param term the election term.
52 * @param votedFor the candidate id that was voted for.
54 void updateAndPersist(long term, @Nullable String votedFor);