Esempio n. 1
0
        public void ElectionResult(NodeHeader node)
        {
            lock (syncLock)
            {
                Header.State = NodeState.Follower;

                nodeList.SetLeader(node);

                leaderNode = nodeList.Leader;
            }
        }
Esempio n. 2
0
 private void FolowerTask()
 {
     try
     {
         leaderNode.Heartbeat();
     }
     catch (Exception)
     {
         leaderNode = null;
         BroadcastElection();
     }
 }
Esempio n. 3
0
        public Node AddNode(NodeHeader nodeHeader)
        {
            Node newNode = null;

            try
            {
                newNode = nodeList.Find(x => x.Header.ID == nodeHeader.ID);

                if (newNode != null)
                {
                    return newNode;
                }

                newNode = new Node(nodeHeader);
                nodeList.Add(newNode);

                newNode.Connect(nodeHeader.NodeAddress);

                OnNodeAdded(newNode.Header);
            }
            catch (Exception)
            {

            }

            return newNode;
        }
Esempio n. 4
0
        private void JoinCluster(NodeHeader networkNode)
        {
            Node node = AddNode(networkNode);

            if (node.Status == NodeStatus.Alive)
            {
                ClusterWelcomeMessage welcome = node.RegisterNode(Header);

                foreach (var item in welcome.NodeList)
                {
                    if (item.ID == Header.ID)
                    {
                        continue;
                    }

                    Node hop = AddNode(item);

                    if (hop.Status == NodeStatus.Alive)
                    {
                        hop.RegisterNode(Header);
                    }
                }
            }

            leaderNode = nodeList.Leader;
        }