Implement behavior common to a RaftActor in all it's states
[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
9 package org.opendaylight.controller.cluster.raft;
10
11 import java.util.concurrent.atomic.AtomicLong;
12
13 /**
14  * ElectionTerm contains information about a RaftActors election term.
15  * <p>
16  * This information includes the last known current term of the RaftActor
17  * and which peer was voted for by the RaftActor in that term
18  * <p>
19  * This class ensures that election term information is persisted
20  */
21 public interface ElectionTerm {
22     /**
23      * latest term server has seen (initialized to 0
24      * on first boot, increases monotonically)
25      */
26     AtomicLong getCurrentTerm();
27
28     /**
29      * candidateId that received vote in current
30      * term (or null if none)
31      */
32     String getVotedFor();
33
34     /**
35      * Called when we need to update the current term either because we received
36      * a message from someone with a more uptodate term or because we just voted
37      * for someone
38      *
39      * @param currentTerm
40      * @param votedFor
41      */
42     void update(long currentTerm, String votedFor);
43 }