// Path: r4j/src/org/r4j/protocol/RequestForVote.java
// public class RequestForVote {
// 
// 	private long term;
// 	
// 	private long lastLogIndex;
// 	
// 	private long lastLogTerm;
// 	
// 	public RequestForVote(long term, long lastLogIndex, long lastLogTerm) {
// 		super();
// 		this.term = term;
// 		this.lastLogIndex = lastLogIndex;
// 		this.lastLogTerm = lastLogTerm;
// 	}
// 
// 	public RequestForVote() {
// 		super();
// 	}
// 
// 	public long getTerm() {
// 		return term;
// 	}
// 
// 	public void setTerm(long term) {
// 		this.term = term;
// 	}
// 
// 	public long getLastLogIndex() {
// 		return lastLogIndex;
// 	}
// 
// 	public void setLastLogIndex(long lastLogIndex) {
// 		this.lastLogIndex = lastLogIndex;
// 	}
// 
// 	public long getLastLogTerm() {
// 		return lastLogTerm;
// 	}
// 
// 	public void setLastLogTerm(long lastLogTerm) {
// 		this.lastLogTerm = lastLogTerm;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return "RequestForVote [term=" + term + ", lastLogIndex="
// 				+ lastLogIndex + ", lastLogTerm=" + lastLogTerm + "]";
// 	}
// 
// }
// 
// Path: r4j/src/org/r4j/protocol/VoteGranted.java
// public class VoteGranted {
// 
// 	private long term;
// 	
// 	public VoteGranted() {
// 		super();
// 	}
// 	
// 	public VoteGranted(long term) {
// 		super();
// 		this.term = term;
// 	}
// 
// 	public long getTerm() {
// 		return term;
// 	}
// 	
// }


import java.util.Random;
import org.r4j.protocol.RequestForVote;
import org.r4j.protocol.VoteGranted;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

package org.r4j;



public class ElectionLogic {
	
	public static long DEFAULT_LEADER_TIMEOUT = 10000L;
	
	public static long DEFAULT_ELECTION_TIMEOUT = 10000L;
	
	public static long PING_LOOP = 1000L;
	
	public static long DEFAULT_STALE_MEMBER_TIMEOUT = DEFAULT_LEADER_TIMEOUT;
	
	private Random random = new Random();
	
	private Logger logger = LoggerFactory.getLogger(Raft.class);
	
	private Election election;

	protected long votedForTerm = -1;

	private long leaderTimestamp = System.currentTimeMillis();
	
	private long leaderTimeout = DEFAULT_LEADER_TIMEOUT;
	
    private long electionTime = -1L;
    
    private long electionEnd = -1L;

    private Raft raft;
    
    public ElectionLogic(Raft raft) {
		super();
		this.raft = raft;
	}



// Path: r4j/src/org/r4j/protocol/RequestForVote.java
// public class RequestForVote {
// 
// 	private long term;
// 	
// 	private long lastLogIndex;
// 	
// 	private long lastLogTerm;
// 	
// 	public RequestForVote(long term, long lastLogIndex, long lastLogTerm) {
// 		super();
// 		this.term = term;
// 		this.lastLogIndex = lastLogIndex;
// 		this.lastLogTerm = lastLogTerm;
// 	}
// 
// 	public RequestForVote() {
// 		super();
// 	}
// 
// 	public long getTerm() {
// 		return term;
// 	}
// 
// 	public void setTerm(long term) {
// 		this.term = term;
// 	}
// 
// 	public long getLastLogIndex() {
// 		return lastLogIndex;
// 	}
// 
// 	public void setLastLogIndex(long lastLogIndex) {
// 		this.lastLogIndex = lastLogIndex;
// 	}
// 
// 	public long getLastLogTerm() {
// 		return lastLogTerm;
// 	}
// 
// 	public void setLastLogTerm(long lastLogTerm) {
// 		this.lastLogTerm = lastLogTerm;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return "RequestForVote [term=" + term + ", lastLogIndex="
// 				+ lastLogIndex + ", lastLogTerm=" + lastLogTerm + "]";
// 	}
// 
// }
// 
// Path: r4j/src/org/r4j/protocol/VoteGranted.java
// public class VoteGranted {
// 
// 	private long term;
// 	
// 	public VoteGranted() {
// 		super();
// 	}
// 	
// 	public VoteGranted(long term) {
// 		super();
// 		this.term = term;
// 	}
// 
// 	public long getTerm() {
// 		return term;
// 	}
// 	
// }


// Path: r4j/src/org/r4j/ElectionLogic.java
import java.util.Random;
import org.r4j.protocol.RequestForVote;
import org.r4j.protocol.VoteGranted;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

package org.r4j;



public class ElectionLogic {
	
	public static long DEFAULT_LEADER_TIMEOUT = 10000L;
	
	public static long DEFAULT_ELECTION_TIMEOUT = 10000L;
	
	public static long PING_LOOP = 1000L;
	
	public static long DEFAULT_STALE_MEMBER_TIMEOUT = DEFAULT_LEADER_TIMEOUT;
	
	private Random random = new Random();
	
	private Logger logger = LoggerFactory.getLogger(Raft.class);
	
	private Election election;

	protected long votedForTerm = -1;

	private long leaderTimestamp = System.currentTimeMillis();
	
	private long leaderTimeout = DEFAULT_LEADER_TIMEOUT;
	
    private long electionTime = -1L;
    
    private long electionEnd = -1L;

    private Raft raft;
    
    public ElectionLogic(Raft raft) {
		super();
		this.raft = raft;
	}



	public void voteReceived(VoteGranted vote) {
