Ejemplo n.º 1
0
        public ClusterService()
        {
            var numberOfNodes = 5;
            var _nodes        = new List <RaftNode>();

            // Create nodes
            for (uint i = 0; i < numberOfNodes; i++)
            {
                var node = new RaftNode(i, new NumeralStateMachine());
                _nodes.Add(node);
            }

            // Adding them to a cluster and configuring them
            foreach (RaftNode node in _nodes)
            {
                var c = new RaftCluster();
                _nodes.ForEach(x => c.AddNode(new ObjectRaftConnector(x.NodeId, x)));
                node.Configure(c);
            }

            this.cluster = _nodes[0].Cluster;

            _nodes.ForEach(node => node.Run());

            this.nodes = _nodes;
        }
Ejemplo n.º 2
0
        private static RaftNode StartNode(Configuration conf)
        {
            var id   = conf.CurrentNode.Id;
            var node = new RaftNode(id, new RaftCore.StateMachine.Implementations.NumeralStateMachine());
            var clusterConfiguration = new RaftCluster();

            foreach (var anotherNode in conf.Nodes)
            {
                clusterConfiguration.AddNode(new APIRaftConnector(anotherNode.Id, anotherNode.BaseUrl + "/RaftApi"));
            }
            node.Configure(clusterConfiguration);
            node.Run();
            return(node);
        }