////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \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)
        {
            LaiYoung_OneRoundChannel channel = (LaiYoung_OneRoundChannel)ChannelFrom(message);

            switch (message.GetHeaderField(bm.pak.MessageType))
            {
            case m.MessageTypes.BaseMessage:
                if (message.GetField(m.baseMessage.Flag))
                {
                    TakeSnapshot();
                }
                else
                {
                    channel.or[c.ork.Arrived] += 1;
                    if (or[p.ork.Recordered])
                    {
                        channel.or[c.ork.State].Add(message.GetField(m.baseMessage.Message));
                    }
                    if (Finished())
                    {
                        PrintResults();
                    }
                }
                break;

            case m.MessageTypes.Presnp:
                channel.or[c.ork.Expected] = message.GetField(m.presnp.NumMsg);
                TakeSnapshot();
                if (Finished())
                {
                    PrintResults();
                }
                break;
            }
        }
예제 #2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn protected virtual void BeforeSendOperation(BaseMessage message)
        ///
        /// \brief Before send operation.
        ///
        /// \par Description.
        ///      This method is used for algorithm specific actions before a send of a message
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 05/04/2017
        ///
        /// \param message  (BaseMessage) - The message.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        protected override void BeforeSendOperation(BaseMessage message)
        {
            LaiYoung_OneRoundChannel channel = (LaiYoung_OneRoundChannel)ChannelTo(message);

            channel.or[c.ork.Sent]++;
            switch (message.GetHeaderField(bm.pak.MessageType))
            {
            case m.MessageTypes.BaseMessage:
                message.AddField(m.baseMessage.Flag, or[p.ork.Recordered]);
                break;

            case m.MessageTypes.Presnp:
                message.AddField(m.presnp.NumMsg, channel.or[c.ork.Sent]);
                break;
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public LaiYoung_OneRoundMessage(LaiYoung_OneRoundNetwork network, object messageType, LaiYoung_OneRoundChannel channel, string messageName, int round = 0, int logicalClock = 0): base(network, messageType, channel, messageName, round, logicalClock)
        ///
        /// \brief Constructor.
        ///
        /// \par Description.
        ///      Construct a message from header parameters.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 14/03/2017
        ///
        /// \param network       (LaiYoung_OneRoundNetwork) - The network.
        /// \param messageType  (dynamic) - Type of the message.
        /// \param channel      (LaiYoung_OneRoundChannel) - The channel.
        /// \param messageName   (string) - Name of the message.
        /// \param round        (Optional)  (int) - The round.
        /// \param logicalClock (Optional)  (int) - The logical clock.
        ///
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public LaiYoung_OneRoundMessage(LaiYoung_OneRoundNetwork network, object messageType, LaiYoung_OneRoundChannel channel, string messageName, int round = 0, int logicalClock = 0) :
            base(network, messageType, channel, messageName, round, logicalClock)
        {
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public LaiYoung_OneRoundMessage(LaiYoung_OneRoundMessage sourceMessage, LaiYoung_OneRoundChannel sendingChannel): base(sourceMessage, sendingChannel)
        ///
        /// \brief Constructor.
        ///
        /// \par Description.
        ///      A message that is duplicated to the source except for the channel parameters.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///      This constructor is useful when you want to forward a message to other channels
        ///
        /// \author Ilanh
        /// \date 14/03/2017
        ///
        /// \param sourceMessage  (LaiYoung_OneRoundMessage) - Message describing the source.
        /// \param sendingChannel (LaiYoung_OneRoundChannel) - The sending channel.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public LaiYoung_OneRoundMessage(LaiYoung_OneRoundNetwork network, LaiYoung_OneRoundMessage sourceMessage, LaiYoung_OneRoundChannel sendingChannel) :
            base(network, sourceMessage, sendingChannel)
        {
        }