public void Start(Zeze.Config config = null) { Create(config); StartModules(); // 启动模块,装载配置什么的。 Zeze.Start(); // 启动数据库 StartService(); // 启动网络等等。 }
public static void Run(string[] args) { string ip = null; int port = 5001; for (int i = 0; i < args.Length; ++i) { switch (args[i]) { case "-ip": ip = args[++i]; break; case "-port": port = int.Parse(args[++i]); break; } } System.Net.IPAddress address = string.IsNullOrEmpty(ip) ? System.Net.IPAddress.Any : System.Net.IPAddress.Parse(ip); var config = new Zeze.Config(); var smconfig = new Zeze.Services.ServiceManager.Conf(); config.AddCustomize(smconfig); config.LoadAndParse(); using var sm = new Zeze.Services.ServiceManager(address, port, config); while (true) { Thread.Sleep(1000); } }
public Raft(StateMachine sm, string RaftName = null, RaftConfig raftconf = null, Zeze.Config config = null, string name = "Zeze.Raft.Server") { if (null == raftconf) { raftconf = RaftConfig.Load(); } raftconf.Verify(); RaftConfig = raftconf; sm.Raft = this; StateMachine = sm; if (false == string.IsNullOrEmpty(RaftName)) { raftconf.Name = RaftName; } if (null == config) { config = Zeze.Config.Load(); } Server = new Server(this, name, config); if (Server.Config.AcceptorCount() != 0) { throw new Exception("Acceptor Found!"); } if (Server.Config.ConnectorCount() != 0) { throw new Exception("Connector Found!"); } if (RaftConfig.Nodes.Count < 3) { throw new Exception("Startup Nodes.Count Must >= 3."); } ImportantThreadPool = new SimpleThreadPool(5, $"Raft.{Name}"); Server.CreateAcceptor(Server, raftconf); Server.CreateConnector(Server, raftconf); LogSequence = new LogSequence(this); RegisterInternalRpc(); StartLeaderLostTimerTask(); LogSequence.StartSnapshotPerDayTimer(); AppDomain.CurrentDomain.ProcessExit += ProcessExit; }
/// <summary> /// /// </summary> /// <param name="raftconf"></param> /// <param name="config"></param> /// <param name="onLeaderChanged"></param> /// <param name="name"></param> public Agent( string name, RaftConfig raftconf = null, Zeze.Config config = null, Action <Agent, Action> onLeaderChanged = null ) { if (null == config) { config = Config.Load(); } Init(new NetClient(this, name, config), raftconf, onLeaderChanged); }
public HandshakeBase(string name, Zeze.Config config) : base(name, config) { }
public NetClient(Agent agent, string name, Zeze.Config config) : base(name, config) { Agent = agent; }
// 多个Raft实例才需要自定义配置名字,否则使用默认名字就可以了。 public Server(Raft raft, string name, Zeze.Config config) : base(name, config) { Raft = raft; }