Пример #1
0
        public void Iterate( MessageList msgList )
        {
            Message tmpMsg;

            //	processing recieved messages from the previous iteration
            while ( this.currentRecieveQ > 0)
            {
                msgList.Find( this.recieveMemory.Dequeue() ).CurrentStatus = MsgStat.Recieved;
                this.currentRecieveQ--;
            }

            //	adding freshly created messages to the main queue
            //	if there is no space left, add them back to the gen queue
            while (this.currentGenerateQ > 0 )
            {
                tmpMsg = msgList.Find( this.genMemory.Dequeue() );
                if ( this.IsFull() )
                {
                    this.genMemory.Enqueue( tmpMsg.Handler );
                }
                else
                {
                    this.memory.Enqueue( tmpMsg.Handler );
                    tmpMsg.CurrentStatus = MsgStat.OnTheWay;
                }
                this.currentGenerateQ--;
            }

            //	sending messages in the base
            while ( this.currentProcQ > 0 )
            {
                tmpMsg = msgList.Find( this.memory.Dequeue() );
                //	if the message has reached its final destination
                if ( this.Handler == tmpMsg.Destination )
                {
                    tmpMsg.CurrentStatus = MsgStat.JustRecieved;
                    this.recieveMemory.Enqueue( tmpMsg.Handler );
                }
                //	if the message has been successfully sent remove it from the memory,
                //	put it in the end of the queue, otherwise.
                else if ( this.sendMsg( tmpMsg ) == false )
                {
                    this.memory.Enqueue( tmpMsg.Handler );
                }
                this.currentProcQ--;
            }

            this.statusSum += this.Status();
        }