//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public override void ReceiveHandling(BaseMessage message) /// /// \brief Receive handling. /// /// \par Description. /// -# This method is activated when a new message arrived to the process /// -# The method processing is done according to their arrival order /// -# If you want to change the order of processing use the ArrangeMessageQ /// /// \par Algorithm. /// /// \par Usage Notes. /// Usually the algorithm of this method is: /// -# if message type is ... perform ... /// -# if message type is ... perform ... /// /// \author Ilan Hindy /// \date 26/01/2017 /// /// \param message The message. //////////////////////////////////////////////////////////////////////////////////////////////////// public override void ReceiveHandling(BaseMessage message) { ChandyLamport_OneRoundChannel sourceChannel = (ChandyLamport_OneRoundChannel)ChannelFrom(message); switch (message[bm.pak.MessageType]) { case m.MessageTypes.BaseMessage: if (or[p.ork.Recordered] && !sourceChannel.or[c.ork.Marked]) { sourceChannel.or[c.ork.State].Add(message[bm.ork.Name]); } break; case m.MessageTypes.Marker: TakeSnapshot(); sourceChannel.or[c.ork.Marked] = true; if (InChannels.All(channel => channel.or[c.ork.Marked])) { PrintResults(); pp[bp.ppk.FrameColor] = KnownColor.Blue; pp[bp.ppk.FrameLineWidth] = 6; } break; } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public override void ReceiveHandling(BaseMessage message) /// /// \brief Receive handling. /// /// \par Description. /// -# This method is activated when a new message arrived to the process /// -# The method processing is done according to their arrival order /// -# If you want to change the order of processing use the ArrangeMessageQueue /// /// \par Algorithm. /// /// \par Usage Notes. /// Usually the algorithm of this method is: /// -# if message type is ... perform ... /// -# if message type is ... perform ... /// /// \author Ilan Hindy /// \date 26/01/2017 /// /// \param message The message. //////////////////////////////////////////////////////////////////////////////////////////////////// public override void ReceiveHandling(BaseMessage message) { switch (message[bm.headerFieldKeys.MessageType]) { case m.MessageTypes.BaseMessage: if (or[p.ork.Recordered] && InChannels.All(channel => !channel.or[c.ork.Marker])) { ChannelFrom(message).or[c.ork.State].Add(message[bm.fieldKeys.MessageName]); } break; case m.MessageTypes.Marker: or[p.ork.Weight] += message[m.marker.Weight]; TakeSnapshot(); ChannelFrom(message).or[c.ork.Marker] = true; if (InChannels.All(channel => channel.or[c.ork.Marker])) { EndRound(); } break; case m.MessageTypes.Report: if (!((AttributeList)or[p.ork.ReceivedMessageFrom]).Any((a => a.Value == (int)message[m.report.Id]))) { or[p.ork.ReceivedMessageFrom].Add(message[m.report.Id]); } if (ea[bp.eak.Initiator]) { or[p.ork.Weight] += message[m.report.Weight]; or[p.ork.Results].Add(message[m.report.Snapshot]); pp[bp.ppk.Text] = GetProcessDefaultName() + "\n" + or[p.ork.Weight]; if (or[p.ork.Weight] == 1) { PrintResults(); if (or[p.ork.Round] < pa[p.pak.MaxRounds]) { TakeSnapshot(); } else { Terminate(); } } } else { SendToNeighbours(message, new List <int> { (int)message[m.report.Id] }); } break; } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public override void ReceiveHandling(BaseMessage message) /// /// \brief Receive handling. /// /// \par Description. /// -# This method is activated when a new message arrived to the process /// -# The method processing is done according to their arrival order /// -# If you want to change the order of processing use the ArrangeMessageQ /// /// \par Algorithm. /// /// \par Usage Notes. /// Usually the algorithm of this method is: /// -# if message type is ... perform ... /// -# if message type is ... perform ... /// /// \author Ilan Hindy /// \date 26/01/2017 /// /// \param message The message. //////////////////////////////////////////////////////////////////////////////////////////////////// public override void ReceiveHandling(BaseMessage message) { ChandyLamportChannel channel = (ChandyLamportChannel)ChannelFrom(message); switch (message[bm.pak.MessageType]) { case m.MessageTypes.BaseMessage: // If the process performed snapshot but still did not get marker from all // it's neighbors : // Save the message - It will be sent as message in the channels if (or[p.ork.Recordered] && !channel.or[c.ork.Marker]) { channel.or[c.ork.State].Add(message[bm.ork.MessageName]); } break; case m.MessageTypes.Marker: // If the process received a marker: // Add the weight in the marker // Perform TakeSnapshot (If first Marker in round - Send Marker to all the neighbors) or[p.ork.Weight] += message[m.marker.Weight]; TakeSnapshot(); // Check if the round ended (Received Marker from all it's neighbors) // Perform EndSnapshot (Send Report, reset variables) channel.or[c.ork.Marker] = true; if (InChannels.All(cnl => cnl.or[c.ork.Marker])) { EndSnapshot(); } break; case m.MessageTypes.Report: // If received a Report Message // If this is not the first report from the source processor in this round // throw the message if (message[bm.pak.Round] < or[bp.ork.Round] || ((AttributeList)or[p.ork.ReceivedMessageFrom]).Any((a => a.Value == (int)message[m.report.Id]))) { break; } else { or[p.ork.ReceivedMessageFrom].Add(message[m.report.Id]); } // If the process is the initiator // Add the message to the results // Add the weight to the process weight // Check condition for end round (weight == 1) // Check condition for end running (round = max rounds) if (ea[bp.eak.Initiator]) { or[p.ork.Results].Add(message[m.report.Snapshot]); or[p.ork.Weight] += message[m.report.Weight]; pp[bp.ppk.Text] = GetProcessDefaultName() + "\n" + or[p.ork.Weight]; if (or[p.ork.Weight] == 1) { PrintResults(); if (or[bp.ork.Round] < pa[p.pak.MaxRounds]) { TakeSnapshot(); } else { Terminate(); } } } // If the process is not the initiator // Propagate the message to all the neighbors else { SendToNeighbours(message, SelectingMethod.Exclude, new List <int> { (int)message[m.report.Id] }); } break; } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public override void ReceiveHandling(BaseMessage message) /// /// \brief Receive handling. /// /// \par Description. /// -# This method is activated when a new message arrived to the process /// -# The method processing is done according to their arrival order /// -# If you want to change the order of processing use the ArrangeMessageQ /// /// \par Algorithm. /// /// \par Usage Notes. /// Usually the algorithm of this method is: /// -# if message type is ... perform ... /// -# if message type is ... perform ... /// /// \author Ilan Hindy /// \date 26/01/2017 /// /// \param message The message. //////////////////////////////////////////////////////////////////////////////////////////////////// //public override void ReceiveHandling(BaseMessage message) //{ //ChandyLamport_NewStyleChannel channel = (ChandyLamport_NewStyleChannel)ChannelFrom(message); //ChandyLamport_NewStyleMessage msg = message as ChandyLamport_NewStyleMessage; //switch ((msg.MessageType) //{ // case BaseMessage: // // If the process performed snapshot but still did not get marker from all // // it's neighbors : // // Save the message - It will be sent as message in the channels // if (Recordered && !channel.Recorderd) // { // channel.State.Add(msg.Name); // } // break; // case (int)Marker: // // If the process received a marker: // // Add the weight in the marker // // Perform TakeSnapshot (If first Marker in round - Send Marker to all the neighbors) // Weight += msg.MarkerWeight; // TakeSnapshot(); // // Check if the round ended (Received Marker from all it's neighbors) // // Perform EndSnapshot (Send Report, reset variables) // channel.or[c.ork.Recorderd] = true; // if (InChannels.All(cnl => cnl.or[c.ork.Recorderd])) // { // EndSnapshot(); // } // // Change the text on the process because the weight changed // pp[bp.ppk.Text] = GetProcessDefaultName() + "\n" + or[p.ork.Weight]; // break; // case m.MessageTypes.Report: // // If received a Report Message // // If this is not the first report from the source processor in this round // // (or the previouse round because a report can come befor or after // // the marker throw the message // if (message[bm.pak.Round] < or[bp.ork.Round] - 1 || // ((AttributeList)or[p.ork.ReceivedMessageFrom]).Any((a => a.Value == (int)message[m.report.Id]))) // { // break; // } // else // { // or[p.ork.ReceivedMessageFrom].Add(message[m.report.Id]); // } // // If the process is the initiator // // Add the message to the results // // Add the weight to the process weight // // Check condition for end round (weight == 1) // // Check condition for end running (round = max rounds) // if (ea[bp.eak.Initiator]) // { // or[p.ork.Results].Add(message[m.report.Snapshot]); // or[p.ork.Weight] += message[m.report.ReportWeight]; // pp[bp.ppk.Text] = GetProcessDefaultName() + "\n" + or[p.ork.Weight]; // if (or[p.ork.Weight] == 1) // { // PrintResults(); // if (or[bp.ork.Round] < pa[p.pak.MaxRounds]) // { // TakeSnapshot(); // } // else // { // Terminate(); // } // } // } // // If the process is not the initiator // // Propagate the message to all the neighbors // else // { // SendToNeighbours(message, SelectingMethod.Exclude, new List<int> { (int)message[m.report.Id] }); // } // break; //} public override void ReceiveHandling(BaseMessage message) { ChandyLamport_NewStyleChannel channel = (ChandyLamport_NewStyleChannel)ChannelFrom(message); ChandyLamport_NewStyleMessage msg = null; msg = message as ChandyLamport_NewStyleMessage; switch (msg.MessageType) { case BaseMessage: // If the process performed snapshot but still did not get marker from all // it's neighbors : // Save the message - It will be sent as message in the channels if (Recorderd && !channel.Recorderd) { channel.State.Add(msg.Name); } break; case Marker: // If the process received a marker: // Add the weight in the marker // Perform TakeSnapshot (If first Marker in round - Send Marker to all the neighbors) Weight += msg.MarkerWeight; TakeSnapshot(); // Check if the round ended (Received Marker from all it's neighbors) // Perform EndSnapshot (Send Report, reset variables) channel.or[c.ork.Recorderd] = true; if (InChannels.All(cnl => ((ChandyLamport_NewStyleChannel)cnl).Recorderd)) { EndSnapshot(); } // Change the text on the process because the weight changed Text = GetProcessDefaultName() + "\n" + Weight; break; case Report: // If received a Report Message // If this is not the first report from the source processor in this round // (or the previouse round because a report can come befor or after // the marker throw the message if (msg.Round < Round - 1 || (ReceivedMessageFrom.Any(a => a.Value == msg.ReporterId))) { break; } else { ReceivedMessageFrom.Add(msg.ReporterId); } // If the process is the initiator // Add the message to the results // Add the weight to the process weight // Check condition for end round (weight == 1) // Check condition for end running (round = max rounds) if (Initiator) { Results.Add(msg.Snapshot); Weight += msg.ReportWeight; Text = GetProcessDefaultName() + "\n" + Weight; if (Weight == 1) { PrintResults(); if (Round < MaxRounds) { TakeSnapshot(); } else { Terminate(); } } } // If the process is not the initiator // Propagate the message to all the neighbors else { SendReport(MessageDataFor_Report(bm.PrmSource.Prms, null, msg.ReporterId, msg.Snapshot, msg.ReportWeight), SelectingMethod.Exclude, new List <int> { (int)msg.ReporterId }); //SendToNeighbours(msg, SelectingMethod.Exclude, new List<int> { (int)msg.ReporterId }); } break; } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public bool Finished() /// /// \brief Finished this object. /// /// \par Description. /// Check if the algorithm finished (marker received from all incomming channels /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 03/06/2018 /// /// \return True if it succeeds, false if it fails. //////////////////////////////////////////////////////////////////////////////////////////////////// public bool Finished() { return(InChannels.All(channel => channel.or[c.ork.Marked])); }