import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import org.opendaylight.controller.cluster.raft.RaftActorContext;
-import org.opendaylight.controller.cluster.raft.base.messages.InitiateInstallSnapshot;
import org.opendaylight.controller.cluster.raft.base.messages.IsolatedLeaderCheck;
import scala.concurrent.duration.FiniteDuration;
public Leader(RaftActorContext context) {
super(context);
- scheduleInstallSnapshotCheck(context.getConfigParams().getIsolatedCheckInterval());
-
scheduleIsolatedLeaderCheck(
new FiniteDuration(context.getConfigParams().getHeartBeatInterval().length() * 10,
context.getConfigParams().getHeartBeatInterval().unit()));
return super.handleMessage(sender, originalMessage);
}
- protected void stopInstallSnapshotSchedule() {
- if (installSnapshotSchedule != null && !installSnapshotSchedule.isCancelled()) {
- installSnapshotSchedule.cancel();
- }
- }
-
- protected void scheduleInstallSnapshotCheck(FiniteDuration interval) {
- if (getFollowerIds().isEmpty()) {
- // Optimization - do not bother scheduling a heartbeat as there are
- // no followers
- return;
- }
-
- stopInstallSnapshotSchedule();
-
- // Schedule a message to send append entries to followers that can
- // accept an append entries with some data in it
- installSnapshotSchedule =
- context.getActorSystem().scheduler().scheduleOnce(
- interval,
- context.getActor(), new InitiateInstallSnapshot(),
- context.getActorSystem().dispatcher(), context.getActor());
- }
-
protected void stopIsolatedLeaderCheckSchedule() {
if (isolatedLeaderCheckSchedule != null && !isolatedLeaderCheckSchedule.isCancelled()) {
isolatedLeaderCheckSchedule.cancel();
@Override
public void close() throws Exception {
- stopInstallSnapshotSchedule();
stopIsolatedLeaderCheckSchedule();
super.close();
}