protected void SendMessage(int destId)
        {
            BaseChannel         channel = OutGoingChannels.First(c => c[ElementDictionaries.ElementAttributes].Value[BaseChannel.ElementAttributeKeys.DestProcess].Value == destId);
            EchoImprovedMessage message = new EchoImprovedMessage(EchoImprovedMessage.MessageTypes.Wave, channel, 0, 0);

            Send(channel[ElementDictionaries.ElementAttributes].Value[BaseChannel.ElementAttributeKeys.DestProcess].Value, message);
        }
Ejemplo n.º 2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private void BackworedReceved(BaseMessage message)
        ///
        /// \brief Backwored receved.
        ///
        /// \brief #### Description.
        ///
        /// \brief #### Algorithm.
        ///
        /// \brief #### Usage Notes.
        ///
        /// \author Ilan Hindy
        /// \date 12/03/2017
        ///
        /// \param message The message.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private void BackworedReceved(BaseMessage message)
        {
            //Mark the outgoing channel
            BaseChannel receiveOutGoingChannel = OutGoingChannels.First(channel => channel[ElementDictionaries.ElementAttributes].Value[BaseChannel.ElementAttributeKeys.DestProcess].Value == message[ElementDictionaries.ElementAttributes].Value[BaseMessage.HeaderFieldKeys.SourceProcess].Value);

            receiveOutGoingChannel[ElementDictionaries.OperationResults].Value[EchoChannel.OperationResultKeys.Status].Value = EchoChannel.Status.Null;

            //Check if all the Outgoing channels that represent a son got answer
            int count = OutGoingChannels.Count(channel => channel[ElementDictionaries.OperationResults].Value[EchoChannel.OperationResultKeys.Status].Value == EchoChannel.Status.SonSent);

            if (count == 0)
            {
                if (ElementAttributes.Value[BaseProcess.ElementAttributeKeys.Initiator].Value == true)
                {
                    if (OperationResults.Value[OperationResultKeys.Round].Value == PrivateAttributes.Value[PrivateAttributeKeys.NumberOfRounds].Value)
                    {
                        //SendToAllNeighbours("Finish", true);
                        Terminate();
                    }
                    else
                    {
                        int round = OperationResults.Value[OperationResultKeys.Round].Value;
                        OperationResults.Value[OperationResultKeys.Round].Value = round + 1;
                        SendToAllNeighbours(EchoMessage.MessageTypes.Forewored, true);
                    }
                }
                else
                {
                    //Send backwored message through the father's channel
                    BaseChannel fatherChannel = OutGoingChannels.First(channel => channel[ElementDictionaries.OperationResults].Value[EchoChannel.OperationResultKeys.Status].Value == EchoChannel.Status.Father);
                    SendBackworedMessage(fatherChannel[ElementDictionaries.ElementAttributes].Value[BaseChannel.ElementAttributeKeys.DestProcess].Value);
                }
            }
        }
Ejemplo n.º 3
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private void SendBackworedMessage(int destProcess)
        ///
        /// \brief Sends a backwored message.
        ///
        /// \brief #### Description.
        ///
        /// \brief #### Algorithm.
        ///
        /// \brief #### Usage Notes.
        ///
        /// \author Ilan Hindy
        /// \date 12/03/2017
        ///
        /// \param destProcess Destination process.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private void SendBackworedMessage(int destProcess)
        {
            BaseChannel senderOutgoingChannel = OutGoingChannels.First(channel => channel[ElementDictionaries.ElementAttributes].Value[BaseChannel.ElementAttributeKeys.DestProcess].Value == destProcess);
            BaseMessage backworedMessage      = new BaseMessage(EchoMessage.MessageTypes.Backwored, senderOutgoingChannel, OperationResults.Value[OperationResultKeys.Round].Value, 0);

            Send(destProcess, backworedMessage);
        }
Ejemplo n.º 4
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private void ForeworedReceived(BaseMessage message)
        ///
        /// \brief Forewored received.
        ///
        /// \brief #### Description.
        ///
        /// \brief #### Algorithm.
        ///
        /// \brief #### Usage Notes.
        ///
        /// \author Ilan Hindy
        /// \date 12/03/2017
        ///
        /// \param message The message.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private void ForeworedReceived(BaseMessage message)
        {
            Logger.Log(Logger.LogMode.MainLogAndProcessLogAndMessageTrace, GetProcessDefaultName(), "ForeworedReceived()", "Message round = " + message[ElementDictionaries.ElementAttributes].Value[BaseMessage.HeaderFieldKeys.Round].Value + " Process round = " + OperationResults.Value[OperationResultKeys.Round].Value.ToString(), message);
            if (message[ElementDictionaries.ElementAttributes].Value[BaseMessage.HeaderFieldKeys.Round].Value > OperationResults.Value[OperationResultKeys.Round].Value)
            {
                //Change the round of the process
                OperationResults.Value[OperationResultKeys.Round].Value = message[ElementDictionaries.ElementAttributes].Value[BaseMessage.HeaderFieldKeys.Round].Value;

                //Mark the father's channel
                BaseChannel fatherOutChannel = OutGoingChannels.First(channel => channel[ElementDictionaries.ElementAttributes].Value[BaseChannel.ElementAttributeKeys.DestProcess].Value == message[ElementDictionaries.ElementAttributes].Value[BaseMessage.HeaderFieldKeys.SourceProcess].Value);
                fatherOutChannel[ElementDictionaries.OperationResults].Value[EchoChannel.OperationResultKeys.Status].Value = EchoChannel.Status.Father;

                //Send forwared messages to all the rest of the channels
                SendToAllNeighbours(EchoMessage.MessageTypes.Forewored, false);

                //If the process has no suns - esend a backword message
                int count = OutGoingChannels.Count(channel => channel[ElementDictionaries.OperationResults].Value[EchoChannel.OperationResultKeys.Status].Value == EchoChannel.Status.SonSent);
                if (count == 0)
                {
                    //Send backwored message to processor that sent the message
                    SendBackworedMessage(message[ElementDictionaries.ElementAttributes].Value[BaseMessage.HeaderFieldKeys.SourceProcess].Value);
                }
            }
            else
            {
                //Send backwored message to processor that sent the message
                SendBackworedMessage(message[ElementDictionaries.ElementAttributes].Value[BaseMessage.HeaderFieldKeys.SourceProcess].Value);
            }
        }