+ private void switchBehavior(SwitchBehavior message) {
+ if(!getRaftActorContext().getRaftPolicy().automaticElectionsEnabled()) {
+ RaftState newState = message.getNewState();
+ if( newState == RaftState.Leader || newState == RaftState.Follower) {
+ switchBehavior(reusableSwitchBehaviorSupplier.handleMessage(getSender(), message));
+ getRaftActorContext().getTermInformation().updateAndPersist(message.getNewTerm(), "");
+ } else {
+ LOG.warn("Switching to behavior : {} - not supported", newState);
+ }
+ }
+ }
+
+ private void switchBehavior(Supplier<RaftActorBehavior> supplier){
+ reusableBehaviorStateHolder.init(getCurrentBehavior());
+
+ setCurrentBehavior(supplier.get());
+
+ handleBehaviorChange(reusableBehaviorStateHolder, getCurrentBehavior());
+ }
+
+ @VisibleForTesting
+ RaftActorSnapshotMessageSupport newRaftActorSnapshotMessageSupport() {
+ return new RaftActorSnapshotMessageSupport(context, getRaftActorSnapshotCohort());
+ }
+