Ejemplo n.º 1
0
 /// <summary>
 /// Initializes the timer with the specified configuration.
 /// </summary>
 private void Setup()
 {
     this.TimerInfo    = (this.ReceivedEvent as TimerSetupEvent).Info;
     this.Owner        = (this.ReceivedEvent as TimerSetupEvent).Owner;
     this.Delay        = (this.ReceivedEvent as TimerSetupEvent).Delay;
     this.TimeoutEvent = new TimerElapsedEvent(this.TimerInfo);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Starts a periodic timer that sends a <see cref="TimerElapsedEvent"/> to this actor after
 /// the specified due time, and then repeats after each specified period. The timer accepts
 /// an optional payload to be used during timeout. The timer can be stopped by invoking the
 /// <see cref="StopTimer"/> method.
 /// </summary>
 /// <remarks>
 /// See <see href="/coyote/learn/programming-models/actors/timers">Using timers in actors</see> for more information.
 /// </remarks>
 /// <param name="startDelay">The amount of time to wait before sending the first timeout event.</param>
 /// <param name="period">The time interval between timeout events.</param>
 /// <param name="customEvent">Optional custom event to raise instead of the default TimerElapsedEvent.</param>
 /// <returns>Handle that contains information about the timer.</returns>
 protected TimerInfo StartPeriodicTimer(TimeSpan startDelay, TimeSpan period, TimerElapsedEvent customEvent = null)
 {
     // The specified due time and period must be valid.
     this.Assert(startDelay.TotalMilliseconds >= 0, "{0} registered a periodic timer with a negative due time.", this.Id);
     this.Assert(period.TotalMilliseconds >= 0, "{0} registered a periodic timer with a negative period.", this.Id);
     return(this.RegisterTimer(startDelay, period, customEvent));
 }
Ejemplo n.º 3
0
 protected virtual bool OnTimeout()
 {
     if (_enabled)
     {
         TimerElapsedEvent?.Invoke(this, new TimerElapsedEventArgs());
     }
     return(_enabled & autoReset);
 }
Ejemplo n.º 4
0
        private void HandleTimeout(Event e)
        {
            TimerElapsedEvent te = (TimerElapsedEvent)e;

            this.WriteMessage("<Client> Handling timeout from timer");

            this.WriteMessage("<Client> Starting a period timer");
            this.PeriodicTimer = this.StartPeriodicTimer(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), new CustomTimerEvent());
        }
Ejemplo n.º 5
0
        protected override EventResult OnElapsed(EventContext context, TimerElapsedEvent @event)
        {
            IEnumerable <ActorInstance> actorInstances = context.CurrentBoard.ActorInstanceLayer.ActorInstances.Where(arg => arg.ActorId == BoardsActor.ActorId);

            foreach (ActorInstanceRandomMoveCommand command in actorInstances.Select(arg => Commands.ActorInstanceRandomMove(arg)))
            {
                context.EnqueueCommand(command);
            }

            return(EventResult.Completed);
        }
        protected override EventResult OnElapsed(EventContext context, TimerElapsedEvent @event)
        {
            IEnumerable<ActorInstance> actorInstances = context.CurrentBoard.ActorInstanceLayer.ActorInstances.Where(arg => arg.ActorId == BoardsActor.ActorId);

            foreach (ActorInstanceRandomMoveCommand command in actorInstances.Select(arg => Commands.ActorInstanceRandomMove(arg)))
            {
                context.EnqueueCommand(command);
            }

            return EventResult.Completed;
        }
 /// <summary>
 /// Initializes the timer with the specified configuration.
 /// </summary>
 private void Setup(Event e)
 {
     this.TimerInfo    = (e as TimerSetupEvent).Info;
     this.Owner        = (e as TimerSetupEvent).Owner;
     this.Delay        = (e as TimerSetupEvent).Delay;
     this.TimeoutEvent = this.TimerInfo.CustomEvent;
     if (this.TimeoutEvent is null)
     {
         this.TimeoutEvent = new TimerElapsedEvent(this.TimerInfo);
     }
     else
     {
         this.TimeoutEvent.Info = this.TimerInfo;
     }
 }
Ejemplo n.º 8
0
        private void HandleTimeoutForPong()
        {
            TimerElapsedEvent e = (this.ReceivedEvent as TimerElapsedEvent);

            if (e.Tid == this.pongTimer)
            {
                tcs.SetResult(true);
                this.Raise(new Halt());
            }
            else
            {
                tcs.SetResult(false);
                this.Raise(new Halt());
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Handle timeout events from the pingTimer.
        /// </summary>
        private async Task HandleTimeoutForPing()
        {
            TimerElapsedEvent e = (this.ReceivedEvent as TimerElapsedEvent);

            // Ensure that we are handling a valid timeout event.
            this.Assert(e.Tid == this.pingTimer, "Handling timeout event from an invalid timer.");

            this.Logger.WriteLine("ping count: {0}", count);

            // Extract the payload
            Object payload = e.Tid.Payload;

            // Increment the count
            count++;

            // Halt pingTimer after handling 10 timeout events
            if (count == 10)
            {
                // Stop the pingTimer, and flush the inbox of all timeout events generated by it
                await StopTimer(pingTimer, flush : true);

                this.Goto <Pong>();
            }
        }
Ejemplo n.º 10
0
            private void HandleTimeoutForPong()
            {
                TimerElapsedEvent e = (this.ReceivedEvent as TimerElapsedEvent);

                this.Assert(e.Tid == this.pongTimer);
            }
Ejemplo n.º 11
0
        protected internal virtual EventResult OnElapsed(EventContext context, TimerElapsedEvent @event)
        {
            context.ThrowIfNull("context");
            @event.ThrowIfNull("event");

            return _eventHandlerCollection.SafeInvoke(context, @event);
        }