public void ElectionResult(NodeHeader node) { lock (syncLock) { Header.State = NodeState.Follower; nodeList.SetLeader(node); leaderNode = nodeList.Leader; } }
private void FolowerTask() { try { leaderNode.Heartbeat(); } catch (Exception) { leaderNode = null; BroadcastElection(); } }
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; }
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; }