Ejemplo n.º 1
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.");
                }
            }
        }
Ejemplo n.º 2
0
 private void    SendElectionResult()
 {
     Messages.ElectBroadcast elect = new Messages.ElectBroadcast(m_configuration.NodeID);
     SendBroadcast(elect);
 }