Initial code/design for an Akka Raft implementation
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / behaviors / Candidate.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.behaviors;
10
11 import akka.actor.ActorRef;
12 import org.opendaylight.controller.cluster.raft.RaftActorContext;
13 import org.opendaylight.controller.cluster.raft.RaftState;
14
15 import java.util.List;
16
17 /**
18  * The behavior of a RaftActor when it is in the CandidateState
19  * <p>
20  * Candidates (ยง5.2):
21  * <ul>
22  * <li> On conversion to candidate, start election:
23  * <ul>
24  * <li> Increment currentTerm
25  * <li> Vote for self
26  * <li> Reset election timer
27  * <li> Send RequestVote RPCs to all other servers
28  * </ul>
29  * <li> If votes received from majority of servers: become leader
30  * <li> If AppendEntries RPC received from new leader: convert to
31  * follower
32  * <li> If election timeout elapses: start new election
33  * </ul>
34  */
35 public class Candidate extends AbstractRaftActorBehavior {
36     private final List<String> peers;
37
38     public Candidate(RaftActorContext context, List<String> peers) {
39         super(context);
40         this.peers = peers;
41     }
42
43     @Override
44     public RaftState handleMessage(ActorRef sender, Object message) {
45         return RaftState.Candidate;
46     }
47 }