Пример #1
0
        private QState Hungry(IQEvent qEvent)
        {
            switch (qEvent.QSignal)
            {
            case (int)QSignals.Entry:
                LogMessage(String.Format("Philosopher {0} is hungry.", m_PhilosopherId));
                TableEvent tableEvent = new TableEvent(DPPSignal.Hungry, m_PhilosopherId);
                LogMessage(String.Format("Philosopher {0} publishes Hungry event.", m_PhilosopherId));
                QF.Instance.Publish(tableEvent);
                return(null);

            case (int)DPPSignal.Eat:
                if (((TableEvent)qEvent).PhilosopherId == m_PhilosopherId)
                {
                    LogMessage(String.Format("Philosopher {0} receives eat signal.", m_PhilosopherId));
                    TransitionTo(m_StateEating, ref s_Tran_Hungry_Eating);
                }
                return(null);

            case (int)QSignals.Exit:
                LogMessage(String.Format("Philosopher {0} is exiting hungry state.", m_PhilosopherId));
                return(null);
            }
            return(this.TopState);
        }
Пример #2
0
        private void LetPhilosopherEat(int philosopherId)
        {
            UseForks(philosopherId);
            TableEvent tableEvent = new TableEvent(DPPSignal.Eat, philosopherId);

            Debug.WriteLine(String.Format("Table publishes Eat event for Philosopher {0}.", philosopherId));

            QF.Instance.Publish(tableEvent);
            Console.WriteLine(String.Format("Philosopher {0} is eating.", philosopherId));
        }
Пример #3
0
        private QState Eating(IQEvent qEvent)
        {
            switch (qEvent.QSignal)
            {
            case (int)QSignals.Entry:
                LogMessage(String.Format("Philosopher {0} is eating.", m_PhilosopherId));
                m_Timer.FireIn(c_EatTime, new PhilosopherEvent(DPPSignal.Timeout));
                return(null);

            case (int)DPPSignal.Timeout:
                TransitionTo(m_StateThinking, ref s_Tran_Eating_Thinking);
                return(null);

            case (int)QSignals.Exit:
                LogMessage(String.Format("Philosopher {0} is exiting eating state.", m_PhilosopherId));
                TableEvent tableEvent = new TableEvent(DPPSignal.Done, m_PhilosopherId);
                LogMessage(String.Format("Philosopher {0} publishes Done event.", m_PhilosopherId));
                QF.Instance.Publish(tableEvent);
                return(null);
            }
            return(this.TopState);
        }
Пример #4
0
        private QState Eating(IQEvent qEvent)
        {
            switch (qEvent.QSignal)
            {
                case (int)QSignals.Entry:
                    LogMessage(String.Format("Philosopher {0} is eating.", m_PhilosopherId));
                    m_Timer.FireIn(c_EatTime, new PhilosopherEvent(DPPSignal.Timeout));
                    return null;

                case (int)DPPSignal.Timeout:
                    TransitionTo(m_StateThinking, ref s_Tran_Eating_Thinking);
                    return null;

                case (int)QSignals.Exit:
                    LogMessage(String.Format("Philosopher {0} is exiting eating state.", m_PhilosopherId));
                    TableEvent tableEvent = new TableEvent(DPPSignal.Done, m_PhilosopherId);
                    LogMessage(String.Format("Philosopher {0} publishes Done event.", m_PhilosopherId));
                    QF.Instance.Publish(tableEvent);
                    return null;
            }
            return this.TopState;
        }
Пример #5
0
        private void LetPhilosopherEat(int philosopherId)
        {
            UseForks(philosopherId);
            TableEvent tableEvent = new TableEvent(DPPSignal.Eat, philosopherId);
            Debug.WriteLine(String.Format("Table publishes Eat event for Philosopher {0}.", philosopherId));

            QF.Instance.Publish(tableEvent);
            Console.WriteLine(String.Format("Philosopher {0} is eating.", philosopherId));
        }
Пример #6
0
        private QState Hungry(IQEvent qEvent)
        {
            switch (qEvent.QSignal)
            {
                case (int)QSignals.Entry:
                    LogMessage(String.Format("Philosopher {0} is hungry.", m_PhilosopherId));
                    TableEvent tableEvent = new TableEvent(DPPSignal.Hungry, m_PhilosopherId);
                    LogMessage(String.Format("Philosopher {0} publishes Hungry event.", m_PhilosopherId));
                    QF.Instance.Publish(tableEvent);
                    return null;

                case (int)DPPSignal.Eat:
                    if (((TableEvent)qEvent).PhilosopherId == m_PhilosopherId)
                    {
                        LogMessage(String.Format("Philosopher {0} receives eat signal.", m_PhilosopherId));
                        TransitionTo(m_StateEating, ref s_Tran_Hungry_Eating);
                    }
                    return null;

                case (int)QSignals.Exit:
                    LogMessage(String.Format("Philosopher {0} is exiting hungry state.", m_PhilosopherId));
                    return null;
            }
            return this.TopState;
        }