RaftGroup meta = RaftGroup.valueOf(RaftGroupId.valueOf(opts.getMetaGroupId()), peers); raftServer = RaftServer.newBuilder() .setStateMachineRegistry(new StateMachine.Registry() { private final StateMachine managementMachine = new ManagementStateMachine(); private final StateMachine logMachine = new LogStateMachine();
public void start() throws IOException { final ServerOpts opts = getServerOpts(); if (opts.getHost() == null) { opts.setHost(LogServiceUtils.getHostName()); } this.lifeCycle = new LifeCycle(this.id); RaftProperties properties = new RaftProperties(); if(opts.getWorkingDir() != null) { RaftServerConfigKeys.setStorageDirs(properties, Collections.singletonList(new File(opts.getWorkingDir()))); } GrpcConfigKeys.Server.setPort(properties, opts.getPort()); NettyConfigKeys.Server.setPort(properties, opts.getPort()); Set<RaftPeer> peers = getPeersFromQuorum(opts.getMetaQuorum()); RaftGroupId raftMetaGroupId = RaftGroupId.valueOf(opts.getMetaGroupId()); RaftGroup metaGroup = RaftGroup.valueOf(raftMetaGroupId, peers); metaStateMachine = new MetaStateMachine(raftMetaGroupId, RaftGroupId.valueOf(opts.getLogServerGroupId())); server = RaftServer.newBuilder() .setGroup(metaGroup) .setServerId(RaftPeerId.valueOf(id)) .setStateMachineRegistry(raftGroupId -> { if(raftGroupId.equals(META_GROUP_ID)) { return metaStateMachine; } return null; }) .setProperties(properties).build(); lifeCycle.startAndTransition(() -> { server.start(); }, IOException.class); }
/** Set the {@link StateMachine} of the server. */ public Builder setStateMachine(StateMachine stateMachine) { return setStateMachineRegistry(gid -> stateMachine); }