Пример #1
0
 public InitTimer(MachineId client, TimerId tid, bool IsPeriodic, int period)
 {
     this.client     = client;
     this.IsPeriodic = IsPeriodic;
     this.Period     = period;
     this.tid        = tid;
 }
Пример #2
0
        private void InitializeTimer()
        {
            InitTimer e = (this.ReceivedEvent as InitTimer);

            this.client     = e.client;
            this.IsPeriodic = e.IsPeriodic;
            this.tid        = e.tid;
            this.Send(this.Id, new RepeatTimeout());
        }
Пример #3
0
        /// <summary>
        /// Start a timer.
        /// </summary>
        /// <param name="payload">Payload of the timeout event.</param>
        /// <param name="IsPeriodic">Specifies whether a periodic timer is desired.</param>
        /// <param name="period">Periodicity of the timeout events in ms.</param>
        /// <returns>The id of the created timer.</returns>
        protected TimerId StartTimer(object payload, int period, bool IsPeriodic)
        {
            // The specified period must be valid
            this.Assert(period >= 0, "Timer period must be non-negative");

            var mid = this.Runtime.CreateMachineId(this.Runtime.GetTimerMachineType());
            var tid = new TimerId(mid, payload);

            this.Runtime.CreateMachine(mid, this.Runtime.GetTimerMachineType(), new InitTimer(this.Id, tid, IsPeriodic, period));

            timers.Add(tid);
            return(tid);
        }
Пример #4
0
        private void InitializeTimer()
        {
            InitTimer e = (this.ReceivedEvent as InitTimer);

            this.Client     = e.client;
            this.IsPeriodic = e.IsPeriodic;
            this.Period     = e.Period;
            this.tid        = e.tid;

            this.IsTimerEnabled = true;
            this.timer          = new System.Timers.Timer(Period);

            if (!IsPeriodic)
            {
                this.timer.AutoReset = false;
            }

            this.timer.Elapsed += ElapsedEventHandler;
            this.timer.Start();
        }
Пример #5
0
        /// <summary>
        /// Stop the timer.
        /// </summary>
        /// <param name="timer">Id of the timer machine which is being stopped.</param>
        /// <param name="flush">Clear the queue of all timeout events generated by "timer".</param>
        protected async Task StopTimer(TimerId timer, bool flush = true)
        {
            // Check if the user is indeed trying to halt a valid timer
            this.Assert(timers.Contains(timer), "Illegal timer-id given to StopTimer");
            timers.Remove(timer);

            this.Send(timer.mid, new HaltTimerEvent(this.Id, flush));

            // Flush the buffer: the timer being stopped sends a markup event to the inbox of this machine.
            // Keep dequeuing eTimeout events (with payload being the timer being stopped), until we see the markup event.
            if (flush)
            {
                while (true)
                {
                    var ev = await this.Receive(Tuple.Create(typeof(Markup), new Func <Event, bool>(e => true)),
                                                Tuple.Create(typeof(TimerElapsedEvent), new Func <Event, bool>(e => (e as TimerElapsedEvent).Tid == timer)));

                    if (ev is Markup)
                    {
                        break;
                    }
                }
            }
        }
Пример #6
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="tid">Tid</param>
 public TimerElapsedEvent(TimerId tid)
 {
     this.Tid = tid;
 }