public void start()

in ratis-logservice/src/main/java/org/apache/ratis/logservice/server/LogServer.java [105:152]


    public void start() throws IOException {
        final ServerOpts opts = getServerOpts();
        Set<RaftPeer> peers = LogServiceUtils.getPeersFromQuorum(opts.getMetaQuorum());
        RaftProperties properties = new RaftProperties();

        // Set properties for the log server state machine
        setRaftProperties(properties);

        InetSocketAddress addr = new InetSocketAddress(opts.getHost(), opts.getPort());
        if(opts.getWorkingDir() != null) {
            RaftServerConfigKeys.setStorageDir(properties, Collections.singletonList(new File(opts.getWorkingDir())));
        }
        String id = opts.getHost() +"_" +  opts.getPort();
        final RaftPeer peer = RaftPeer.newBuilder().setId(id).setAddress(addr).build();
        final RaftGroupId logServerGroupId = RaftGroupId.valueOf(opts.getLogServerGroupId());
        RaftGroup all = RaftGroup.valueOf(logServerGroupId, peer);
        RaftGroup meta = RaftGroup.valueOf(RaftGroupId.valueOf(opts.getMetaGroupId()), peers);

        // Make sure that we aren't setting any invalid/harmful properties
        validateRaftProperties(properties);

        raftServer = RaftServer.newBuilder()
                .setStateMachineRegistry(new StateMachine.Registry() {
                    @Override
                    public StateMachine apply(RaftGroupId raftGroupId) {
                        // TODO this looks wrong. Why isn't this metaGroupId?
                        if(raftGroupId.equals(logServerGroupId)) {
                            return new ManagementStateMachine();
                        }
                        return new LogStateMachine(properties);
                    }
                })
                .setProperties(properties)
                .setServerId(RaftPeerId.valueOf(id))
                .setGroup(all)
                .build();
        raftServer.start();

        metaClient = RaftClient.newBuilder()
                .setRaftGroup(meta)
                .setClientId(ClientId.randomId())
                .setProperties(properties)
                .build();
        metaClient.io().send(() -> MetaServiceProtoUtil.toPingRequestProto(peer).toByteString());
        daemon = new Daemon(new HeartbeatSender(RaftPeer.newBuilder().setId(raftServer.getId()).build()),
                "heartbeat-Sender"+raftServer.getId());
        daemon.start();
    }