// 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;

			setElectionTime(-1L);
			this.raft.getTerm().newTerm();
			this.election = new Election(raft.getMembers().size() + 1, this.raft.getTerm().getCurrent());
			for (ClusterMember m : raft.getMembers()) {
				m.getChannel().send(raft, new RequestForVote(this.raft.getTerm().getCurrent(), raft.getLog().getLastIndex(), raft.getLog().getLastTerm()));
			}
			if (vote(null, new RequestForVote(this.raft.getTerm().getCurrent(), raft.getLog().getLastIndex(), raft.getLog().getLastTerm()))) {
				voteReceived(new VoteGranted(this.raft.getTerm().getCurrent()));				
			}
			this.electionEnd = time + DEFAULT_ELECTION_TIMEOUT;
			logger.info("Starting election for: " + this.raft.getTerm().getCurrent());
			return DEFAULT_ELECTION_TIMEOUT;
		} else {
			return electionTime - time;
		}
	}

	public long candidateLoop() {
		long time = System.currentTimeMillis();
		if (electionEnd > -1 && electionEnd <= time) {
			//timeout
			setFollower();
		} else {
			if (electionEnd < 0) {
				return tryStartElection();				
			}
		}
		return -1L;
	}


// 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;

			setElectionTime(-1L);
			this.raft.getTerm().newTerm();
			this.election = new Election(raft.getMembers().size() + 1, this.raft.getTerm().getCurrent());
			for (ClusterMember m : raft.getMembers()) {
				m.getChannel().send(raft, new RequestForVote(this.raft.getTerm().getCurrent(), raft.getLog().getLastIndex(), raft.getLog().getLastTerm()));
			}
			if (vote(null, new RequestForVote(this.raft.getTerm().getCurrent(), raft.getLog().getLastIndex(), raft.getLog().getLastTerm()))) {
				voteReceived(new VoteGranted(this.raft.getTerm().getCurrent()));				
			}
			this.electionEnd = time + DEFAULT_ELECTION_TIMEOUT;
			logger.info("Starting election for: " + this.raft.getTerm().getCurrent());
			return DEFAULT_ELECTION_TIMEOUT;
		} else {
			return electionTime - time;
		}
	}

	public long candidateLoop() {
		long time = System.currentTimeMillis();
		if (electionEnd > -1 && electionEnd <= time) {
			//timeout
			setFollower();
		} else {
			if (electionEnd < 0) {
				return tryStartElection();				
			}
		}
		return -1L;
	}


	public boolean vote(ClusterMember clusterMember, RequestForVote vote) {
