ServerState(RaftPeerId id, RaftGroup group, RaftProperties prop,
RaftServerImpl server, StateMachine stateMachine)
throws IOException {
this.selfId = id;
this.server = server;
RaftConfiguration initialConf = RaftConfiguration.newBuilder()
.setConf(group.getPeers()).build();
configurationManager = new ConfigurationManager(initialConf);
final File dir = RaftServerConfigKeys.storageDir(prop);
storage = new RaftStorage(new File(dir, group.getGroupId().toString()),
RaftServerConstants.StartupOption.REGULAR);
snapshotManager = new SnapshotManager(storage, id);
long lastApplied = initStatemachine(stateMachine, prop);
leaderId = null;
log = initLog(id, prop, lastApplied, entry -> {
if (entry.getLogEntryBodyCase() == CONFIGURATIONENTRY) {
configurationManager.addConfiguration(entry.getIndex(),
ServerProtoUtils.toRaftConfiguration(entry.getIndex(),
entry.getConfigurationEntry()));
}
});
RaftLog.Metadata metadata = log.loadMetadata();
currentTerm = metadata.getTerm();
votedFor = metadata.getVotedFor();
stateMachineUpdater = new StateMachineUpdater(stateMachine, server, log,
lastApplied, prop);
}