示例#1
0
        private void HandleElectionEnd(ElectionEndMessage msg)
        {
            Debug.WriteLine("HandleElectionEnd");
            Reset();

            if (msg.SourceID == _config.ID)
            {
                NotifyElection();
            }
        }
示例#2
0
        private void HandleElectionAck(ElectionAckMessage msg)
        {
            Debug.WriteLine("HandleElectionAck");
            _acksRx++;

            if (_acksRx == _nodeCount - 1)
            {
                Debug.WriteLine(string.Format("Enter if: _acksRx = {0}, _nodeCount = {1}", _acksRx, _nodeCount));
                var myProposal = _proposals[_config.ID];

                bool isLeader = true;
                foreach (var proposal in _proposals.Values)
                {
                    if (proposal.SourceID != _config.ID)
                    {
                        if (proposal.IsGreaterThan(myProposal))
                        {
                            isLeader = false;
                            break;
                        }
                    }
                }

                if (isLeader)
                {
                    var joinEnd = new ElectionEndMessage()
                    {
                        SourceID      = _config.ID,
                        DestinationID = Constants.NULL_DESTINATION,
                    };

                    Debug.WriteLine(string.Format("TX {0}", joinEnd.Type));
                    SendMessage(joinEnd, _group);
                }
            }
        }