Пример #1
0
        public void             ElectionOk(Messages.ElectionOk ok)
        {
            if (m_oks != null)
            {
                m_oks[ok.senderId] = true;
                LogMessage(this, "Election ok message from: [" + ok.senderId + "]");

                CheckIfWon();
            }
            else
            {
                LogMessage(this, "Unexpected electionOK message from: [" + ok.senderId + "]");
            }
        }
Пример #2
0
        private void    QueryMessage()
        {
            foreach (var item in m_protocol.MessageQueue.GetConsumingEnumerable())
            {
                var json = (JObject)JsonConvert.DeserializeObject(item.Msg);
                var type = json["type"].ToString();

                if (type == "electionOK")
                {
                    Messages.ElectionOk electionOk = JsonConvert.DeserializeObject <Messages.ElectionOk>(item.Msg);
                    m_election.ElectionOk(electionOk);
                }
                else if (type == "electionBroadcast")
                {
                    Messages.ElectionBroadcast electionBroadcast = JsonConvert.DeserializeObject <Messages.ElectionBroadcast>(item.Msg);
                    m_election.ElectionBroadcast(electionBroadcast);
                    m_elected = false;
                }
                else if (type == "electBroadcast")
                {
                    Messages.ElectBroadcast electBroadcast = JsonConvert.DeserializeObject <Messages.ElectBroadcast>(item.Msg);
                    m_election.ElectBroadcast(electBroadcast);
                }
                else if (m_elected)
                {
                    if (m_elected && type == "request")
                    {
                        Messages.Request request = JsonConvert.DeserializeObject <Messages.Request>(item.Msg);
                        m_suzuki.RequestMessage(request);
                    }
                    else if (m_elected && type == "token")
                    {
                        Messages.TokenMessage token = JsonConvert.DeserializeObject <Messages.TokenMessage>(item.Msg);
                        m_suzuki.TokenMessage(token);
                    }
                }
                else
                {
                    LogMessage(this, "Ignored " + type + " Waiting for election.");
                }
            }
        }
Пример #3
0
        public void             ElectionBroadcast(Messages.ElectionBroadcast election)
        {
            if (election.senderId < m_configuration.NodeID)
            {
                if (m_oks == null)
                {
                    StartElection();
                    LogMessage(this, "Election broadcast from [" + election.senderId + "]. Broadcasting number.");
                }
                else
                {
                    LogMessage(this, "Election broadcast from [" + election.senderId + "]. Broadcast already sent.");
                }
            }
            else if (election.senderId > m_configuration.NodeID)
            {
                if (!NoElectionResponse)
                {
                    Messages.ElectionOk ok = new Messages.ElectionOk(m_configuration.NodeID);

                    var senderDesc = m_configuration.FindNode(election.senderId);
                    Send(ok, senderDesc.Port, senderDesc.NodeIP);

                    LogMessage(this, "Election broadcast from [" + election.senderId + "]. Sending OK.");
                }
                else
                {
                    LogMessage(this, "ElectionOk to: [" + election.senderId + "] intentionally not send. Check Menu -> Debug -> No election response");
                }

                // Don't take part in election anymore.
                m_electionOkTimeout.Stop();
            }
            else
            {
                LogMessage(this, "Duplicate node with the same id in network");
            }
        }