Initial code/design for an Akka Raft implementation
[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 import java.util.concurrent.atomic.AtomicLong;
12
13 public class ElectionTermImpl implements ElectionTerm{
14     /**
15      * Identifier of the actor whose election term information this is
16      */
17     private final String id;
18
19     private AtomicLong currentTerm;
20
21     private String votedFor;
22
23     public ElectionTermImpl(String id) {
24         this.id = id;
25
26         // TODO: Read currentTerm from some persistent state
27         currentTerm = new AtomicLong(0);
28
29         // TODO: Read votedFor from some file
30         votedFor = "";
31     }
32
33     public AtomicLong getCurrentTerm() {
34         return currentTerm;
35     }
36
37     public String getVotedFor() {
38         return votedFor;
39     }
40
41     public void update(AtomicLong currentTerm, String votedFor){
42         this.currentTerm = currentTerm;
43         this.votedFor = votedFor;
44
45         // TODO : Write to some persistent state
46     }
47 }