+ private long replicatedToAllIndex = -1;
+
+ AbstractRaftActorBehavior(final RaftActorContext context, final RaftState state) {
+ this.context = Preconditions.checkNotNull(context);
+ this.state = Preconditions.checkNotNull(state);
+ this.log = context.getLogger();
+
+ logName = String.format("%s (%s)", context.getId(), state);
+ }
+
+ public static RaftActorBehavior createBehavior(final RaftActorContext context, final RaftState state) {
+ switch (state) {
+ case Candidate:
+ return new Candidate(context);
+ case Follower:
+ return new Follower(context);
+ case IsolatedLeader:
+ return new IsolatedLeader(context);
+ case Leader:
+ return new Leader(context);
+ case PreLeader:
+ return new PreLeader(context);
+ default:
+ throw new IllegalArgumentException("Unhandled state " + state);
+ }
+ }
+
+ @Override
+ public final RaftState state() {
+ return state;
+ }