-public class Leader extends AbstractRaftActorBehavior {
-
-
- private final Map<String, FollowerLogInformation> followerToLog =
- new HashMap();
-
- private final Map<String, ActorSelection> followerToActor = new HashMap<>();
-
- private Cancellable heartbeatCancel = null;
-
- private List<ClientRequestTracker> trackerList = new ArrayList<>();
-
- private final int minReplicationCount;
-
- public Leader(RaftActorContext context) {
- super(context);
-
- if (lastIndex() >= 0) {
- context.setCommitIndex(lastIndex());
- }
-
- for (String followerId : context.getPeerAddresses().keySet()) {
- FollowerLogInformation followerLogInformation =
- new FollowerLogInformationImpl(followerId,
- new AtomicLong(lastIndex()),
- new AtomicLong(-1));
-
- followerToActor.put(followerId,
- context.actorSelection(context.getPeerAddress(followerId)));
-
- followerToLog.put(followerId, followerLogInformation);
-
- }
-
- if (followerToActor.size() > 0) {
- minReplicationCount = (followerToActor.size() + 1) / 2 + 1;
- } else {
- minReplicationCount = 0;
- }
-
-
- // Immediately schedule a heartbeat
- // Upon election: send initial empty AppendEntries RPCs
- // (heartbeat) to each server; repeat during idle periods to
- // prevent election timeouts (§5.2)
- scheduleHeartBeat(new FiniteDuration(0, TimeUnit.SECONDS));
-
-
+public class Leader extends AbstractLeader {
+ /**
+ * Internal message sent to periodically check if this leader has become isolated and should transition
+ * to {@link IsolatedLeader}.
+ */
+ @VisibleForTesting
+ static final Object ISOLATED_LEADER_CHECK = new Object();
+
+ private final Stopwatch isolatedLeaderCheck = Stopwatch.createStarted();
+ private @Nullable LeadershipTransferContext leadershipTransferContext;
+
+ Leader(RaftActorContext context, @Nullable AbstractLeader initializeFromLeader) {
+ super(context, RaftState.Leader, initializeFromLeader);