import akka.actor.ActorRef;
import akka.actor.Cancellable;
-import java.util.HashSet;
import java.util.Random;
-import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.opendaylight.controller.cluster.raft.ClientRequestTracker;
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.SerializationUtils;
-import org.opendaylight.controller.cluster.raft.ServerConfigurationPayload;
-import org.opendaylight.controller.cluster.raft.VotingState;
import org.opendaylight.controller.cluster.raft.base.messages.ApplyJournalEntries;
import org.opendaylight.controller.cluster.raft.base.messages.ApplyState;
import org.opendaylight.controller.cluster.raft.base.messages.ElectionTimeout;
}
}
+ protected boolean canStartElection() {
+ return context.getRaftPolicy().automaticElectionsEnabled() && context.isVotingMember();
+ }
+
/**
* schedule a new election
*
protected void scheduleElection(FiniteDuration interval) {
stopElection();
- // Schedule an election. When the scheduler triggers an ElectionTimeout
- // message is sent to itself
- electionCancel =
- context.getActorSystem().scheduler().scheduleOnce(interval,
- context.getActor(), ELECTION_TIMEOUT,
- context.getActorSystem().dispatcher(), context.getActor());
+ if(canStartElection()) {
+ // Schedule an election. When the scheduler triggers an ElectionTimeout message is sent to itself
+ electionCancel = context.getActorSystem().scheduler().scheduleOnce(interval, context.getActor(),
+ ELECTION_TIMEOUT,context.getActorSystem().dispatcher(), context.getActor());
+ }
}
/**
protected String getId(){
return context.getId();
}
-
- public void applyServerConfiguration(ServerConfigurationPayload serverConfig) {
- Set<String> currentPeers = new HashSet<>(context.getPeerIds());
- for(String peerId: serverConfig.getNewServerConfig()) {
- if(!getId().equals(peerId)) {
- if(!currentPeers.contains(peerId)) {
- context.addToPeers(peerId, null, VotingState.VOTING);
- } else {
- currentPeers.remove(peerId);
- }
- }
- }
-
- for(String peerIdToRemove: currentPeers) {
- context.removePeer(peerIdToRemove);
- }
- }
}