private void RequestCriticalSection() { UInt64 seqNumber = IncrementSeqNumber(); Messages.Request request = new Messages.Request(m_configuration.NodeID, seqNumber); SendBroadcast(request); m_tokenReceiveTimeout.Start(); }
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."); } } }
public void RequestMessage(Messages.Request request) { var nodeId = request.senderId; var lastReqId = m_requestNumbers[nodeId]; m_requestNumbers[nodeId] = Math.Max(lastReqId, request.value.requestNumber); lock ( m_tokenLock ) { // We can immediatly send token. if (m_token != null && m_possesedCriticalSection == false && m_requestNumbers[nodeId] == m_token.GetSeqNumber(nodeId) + 1) { SendToken(nodeId); } else { // Note: we don't enqueue node here. This happens while releasing critical section. //m_token.Queue.Enqueue( nodeId ); } } }