- protected RaftActorBehavior handleAppendEntriesReply(ActorRef sender, AppendEntriesReply appendEntriesReply) {
- RaftActorBehavior returnBehavior = super.handleAppendEntriesReply(sender, appendEntriesReply);
-
- if(context.getCommitIndex() >= context.getReplicatedLog().lastIndex()) {
- // We've committed all entries - we can switch to Leader.
- returnBehavior = internalSwitchBehavior(new Leader(context, this));
+ public RaftActorBehavior handleMessage(ActorRef sender, Object message) {
+ if (message instanceof ApplyState) {
+ log.debug("{}: Received {} - lastApplied: {}, lastIndex: {}", logName(), message, context.getLastApplied(),
+ context.getReplicatedLog().lastIndex());
+ if (context.getLastApplied() >= context.getReplicatedLog().lastIndex()) {
+ // We've applied all entries - we can switch to Leader.
+ return internalSwitchBehavior(new Leader(context, this));
+ } else {
+ return this;
+ }
+ } else {
+ return super.handleMessage(sender, message);