Exemplo n.º 1
0
        private void SendToken(UInt32 nodeId)
        {
            Messages.TokenMessage token = null;

            lock ( m_tokenLock )
            {
                token   = new Messages.TokenMessage(m_configuration.NodeID, m_token);
                m_token = null;
            }

            var nodeDesc = m_configuration.FindNode(nodeId);

            //var jsonString = JsonConvert.SerializeObject( token );

            Send(token, nodeDesc.Port, nodeDesc.NodeIP);

            LogMessage(this, "Token sended to node: [" + nodeDesc.NodeID + "] " + nodeDesc.NodeIP + " Port: " + nodeDesc.Port);
        }
Exemplo n.º 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.");
                }
            }
        }
Exemplo n.º 3
0
        public void TokenMessage(Messages.TokenMessage msg)
        {
            lock ( m_tokenLock )
            {
                var nodeDesc = m_configuration.FindNode(msg.senderId);

                if (m_token != null)
                {
                    LogMessage(this, "Duplicate tokend received from node [" + nodeDesc.NodeID + "] " + nodeDesc.NodeIP + " Port: " + nodeDesc.Port);

                    // @todo: Hmmm, consider merging tokens.
                    return;
                }

                LogMessage(this, "Tokend received from node [" + nodeDesc.NodeID + "] " + nodeDesc.NodeIP + " Port: " + nodeDesc.Port);

                m_token = msg.value;
                ReleaseSemaphore();
            }
        }