use of com.alipay.sofa.jraft.test.atomic.server.processor.SetCommandProcessor in project sofa-jraft by sofastack.
the class AtomicServer method start.
public void start() throws IOException {
PeerId serverId = new PeerId();
if (!serverId.parse(conf.getServerAddress())) {
throw new IllegalArgumentException("Fail to parse serverId:" + conf.getServerAddress());
}
FileUtils.forceMkdir(new File(conf.getDataPath()));
// The same in-process raft group shares the same RPC Server.
RpcServer rpcServer = RaftRpcServerFactory.createRaftRpcServer(serverId.getEndpoint());
// Register biz handler
rpcServer.registerProcessor(new GetSlotsCommandProcessor(this));
rpcServer.registerProcessor(new GetCommandProcessor(this));
rpcServer.registerProcessor(new IncrementAndGetCommandProcessor(this));
rpcServer.registerProcessor(new CompareAndSetCommandProcessor(this));
rpcServer.registerProcessor(new SetCommandProcessor(this));
long step = conf.getMaxSlot() / totalSlots;
if (conf.getMaxSlot() % totalSlots > 0) {
step = step + 1;
}
for (int i = 0; i < totalSlots; i++) {
long min = i * step;
long mayMax = (i + 1) * step;
long max = mayMax > conf.getMaxSlot() || mayMax <= 0 ? conf.getMaxSlot() : mayMax;
StartupConf nodeConf = new StartupConf();
String nodeDataPath = conf.getDataPath() + File.separator + i;
nodeConf.setDataPath(nodeDataPath);
String nodeGroup = conf.getGroupId() + "_" + i;
nodeConf.setGroupId(nodeGroup);
nodeConf.setMaxSlot(max);
nodeConf.setMinSlot(min);
nodeConf.setConf(conf.getConf());
nodeConf.setServerAddress(conf.getServerAddress());
nodeConf.setTotalSlots(conf.getTotalSlots());
LOG.info("Starting range node {}-{} with conf {}", min, max, nodeConf);
nodes.put(i * step, AtomicRangeGroup.start(nodeConf, rpcServer));
groups.put(i * step, nodeGroup);
}
}
Aggregations