Example #1
0
File: App.cs Project: e2wugui/zeze
 public void Start(Zeze.Config config = null)
 {
     Create(config);
     StartModules(); // 启动模块,装载配置什么的。
     Zeze.Start();   // 启动数据库
     StartService(); // 启动网络等等。
 }
Example #2
0
        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);
            }
        }
Example #3
0
        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;
        }
Example #4
0
        /// <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);
        }
Example #5
0
 public HandshakeBase(string name, Zeze.Config config) : base(name, config)
 {
 }
Example #6
0
 public NetClient(Agent agent, string name, Zeze.Config config)
     : base(name, config)
 {
     Agent = agent;
 }
Example #7
0
 // 多个Raft实例才需要自定义配置名字,否则使用默认名字就可以了。
 public Server(Raft raft, string name, Zeze.Config config) : base(name, config)
 {
     Raft = raft;
 }