Search in sources :

Example 1 with GetCommandProcessor

use of com.alipay.sofa.jraft.test.atomic.server.processor.GetCommandProcessor 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);
    }
}
Also used : IncrementAndGetCommandProcessor(com.alipay.sofa.jraft.test.atomic.server.processor.IncrementAndGetCommandProcessor) CompareAndSetCommandProcessor(com.alipay.sofa.jraft.test.atomic.server.processor.CompareAndSetCommandProcessor) SetCommandProcessor(com.alipay.sofa.jraft.test.atomic.server.processor.SetCommandProcessor) CompareAndSetCommandProcessor(com.alipay.sofa.jraft.test.atomic.server.processor.CompareAndSetCommandProcessor) RpcServer(com.alipay.sofa.jraft.rpc.RpcServer) GetSlotsCommandProcessor(com.alipay.sofa.jraft.test.atomic.server.processor.GetSlotsCommandProcessor) GetCommandProcessor(com.alipay.sofa.jraft.test.atomic.server.processor.GetCommandProcessor) IncrementAndGetCommandProcessor(com.alipay.sofa.jraft.test.atomic.server.processor.IncrementAndGetCommandProcessor) File(java.io.File) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Aggregations

PeerId (com.alipay.sofa.jraft.entity.PeerId)1 RpcServer (com.alipay.sofa.jraft.rpc.RpcServer)1 CompareAndSetCommandProcessor (com.alipay.sofa.jraft.test.atomic.server.processor.CompareAndSetCommandProcessor)1 GetCommandProcessor (com.alipay.sofa.jraft.test.atomic.server.processor.GetCommandProcessor)1 GetSlotsCommandProcessor (com.alipay.sofa.jraft.test.atomic.server.processor.GetSlotsCommandProcessor)1 IncrementAndGetCommandProcessor (com.alipay.sofa.jraft.test.atomic.server.processor.IncrementAndGetCommandProcessor)1 SetCommandProcessor (com.alipay.sofa.jraft.test.atomic.server.processor.SetCommandProcessor)1 File (java.io.File)1