import org.opendaylight.controller.cluster.raft.RaftActorContext;
import org.opendaylight.controller.cluster.raft.RaftState;
import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry;
-import org.opendaylight.controller.cluster.raft.internal.messages.ApplyState;
-import org.opendaylight.controller.cluster.raft.internal.messages.ElectionTimeout;
+import org.opendaylight.controller.cluster.raft.SerializationUtils;
+import org.opendaylight.controller.cluster.raft.base.messages.ApplyState;
+import org.opendaylight.controller.cluster.raft.base.messages.ElectionTimeout;
import org.opendaylight.controller.cluster.raft.messages.AppendEntries;
import org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply;
import org.opendaylight.controller.cluster.raft.messages.RequestVote;
*/
protected final RaftActorContext context;
- /**
- * The maximum election time variance
- */
- private static final int ELECTION_TIME_MAX_VARIANCE = 100;
-
- /**
- * The interval at which a heart beat message will be sent to the remote
- * RaftActor
- * <p/>
- * Since this is set to 100 milliseconds the Election timeout should be
- * at least 200 milliseconds
- */
- protected static final FiniteDuration HEART_BEAT_INTERVAL =
- new FiniteDuration(100, TimeUnit.MILLISECONDS);
-
- /**
- * The interval in which a new election would get triggered if no leader is found
- */
- private static final long ELECTION_TIME_INTERVAL =
- HEART_BEAT_INTERVAL.toMillis() * 2;
-
/**
*
*/
if (candidateLatest) {
grantVote = true;
- context.getTermInformation().update(requestVote.getTerm(),
+ context.getTermInformation().updateAndPersist(requestVote.getTerm(),
requestVote.getCandidateId());
}
}
* @return
*/
protected FiniteDuration electionDuration() {
- long variance = new Random().nextInt(ELECTION_TIME_MAX_VARIANCE);
- return new FiniteDuration(ELECTION_TIME_INTERVAL + variance,
- TimeUnit.MILLISECONDS);
+ long variance = new Random().nextInt(context.getConfigParams().getElectionTimeVariance());
+ return context.getConfigParams().getElectionTimeOutInterval().$plus(
+ new FiniteDuration(variance, TimeUnit.MILLISECONDS));
}
/**
context.setLastApplied(index);
}
+ protected Object fromSerializableMessage(Object serializable){
+ return SerializationUtils.fromSerializable(serializable);
+ }
+
@Override
public RaftState handleMessage(ActorRef sender, Object message) {
if (message instanceof AppendEntries) {