Properly handle RequestVote in all states
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / ElectionTermImpl.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 public class ElectionTermImpl implements ElectionTerm{
12     /**
13      * Identifier of the actor whose election term information this is
14      */
15     private final String id;
16
17     private long currentTerm;
18
19     private String votedFor;
20
21     public ElectionTermImpl(String id) {
22         this.id = id;
23
24         // TODO: Read currentTerm from some persistent state
25         currentTerm = 0;
26
27         // TODO: Read votedFor from some file
28         votedFor = "";
29     }
30
31     public long getCurrentTerm() {
32         return currentTerm;
33     }
34
35     public String getVotedFor() {
36         return votedFor;
37     }
38
39     public void update(long currentTerm, String votedFor){
40         this.currentTerm = currentTerm;
41         this.votedFor = votedFor;
42
43         // TODO : Write to some persistent state
44     }
45 }