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.
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.
21 * This class ensures that election term information is persisted.
23 public interface ElectionTerm {
25 * Returns the current leader's Raft term.
27 * @return the current leader's Raft term.
29 long getCurrentTerm();
32 * Returns the id of the candidate that this server voted for in current term.
34 * @return candidate id that received the vote or null if no candidate was voted for.
40 * This method updates the in-memory election term state. This method should be called when recovering election
41 * state from persistent storage.
43 * @param term the election term.
44 * @param votedFor the candidate id that was voted for.
46 void update(long term, @Nullable String votedFor);
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
53 * @param term the election term.
54 * @param votedFor the candidate id that was voted for.
56 void updateAndPersist(long term, @Nullable String votedFor);