Пример #1
0
        public void ReceivedResponse(IActorRef deviceActor, ITemperatureReading reading, HashSet <IActorRef> stillWaiting, Dictionary <string, ITemperatureReading> repliesSoFar)
        {
            Console.WriteLine(JsonConvert.SerializeObject(new
            {
                Message     = $"{GetType().Name}.ReceivedResponse",
                deviceActor = deviceActor.ToString(),
                reading,
                stillWaitingCount = stillWaiting.Count,
                repliesSoFarCount = repliesSoFar.Count
            }, Formatting.Indented));
            Context.Unwatch(deviceActor);
            string deviceId = ActorToDeviceId[deviceActor];

            stillWaiting.Remove(deviceActor);

            repliesSoFar.Add(deviceId, reading);

            if (stillWaiting.Count == 0)
            {
                Requester.Tell(new RespondAllTemperatures(RequestId, repliesSoFar));
                Context.Stop(Self);
            }
            else
            {
                Context.Become(WaitingForReplies(repliesSoFar, stillWaiting));
            }
        }
Пример #2
0
 /// <summary>
 /// Receive one message of the specified type from the test actor and assert that the given
 /// predicate accepts it and was sent by the specified sender
 /// Wait time is bounded by the given duration if specified.
 /// If not specified, wait time is bounded by remaining time for execution of the innermost enclosing 'within'
 /// block, if inside a 'within' block; otherwise by the config value
 /// "akka.test.single-expect-default".
 /// Use this variant to implement more complicated or conditional processing.
 /// </summary>
 /// <typeparam name="T">TBD</typeparam>
 /// <param name="sender">TBD</param>
 /// <param name="isMessage">TBD</param>
 /// <param name="timeout">TBD</param>
 /// <param name="hint">TBD</param>
 /// <returns>TBD</returns>
 public T ExpectMsgFrom <T>(IActorRef sender, Predicate <T> isMessage, TimeSpan?timeout = null, string hint = null)
 {
     return(InternalExpectMsg <T>(RemainingOrDilated(timeout), (m, s) =>
     {
         _assertions.AssertEqual(sender, s, FormatWrongSenderMessage(s, sender.ToString(), hint));
         if (isMessage != null)
         {
             AssertPredicateIsTrueForMessage(isMessage, m, hint);
         }
     }, hint));
 }
Пример #3
0
        /// <summary>
        /// Posts the specified envelope.
        /// </summary>
        /// <param name="receiver"></param>
        /// <param name="envelope"> The envelope. </param>
        public override void Post(IActorRef receiver, Envelope envelope)
        {
            if (_isClosed)
            {
                return;
            }

            hasUnscheduledMessages = true;
            if (envelope.Message is ISystemMessage)
            {
                Mailbox.DebugPrint("{0} enqueued system message {1} to {2}", ActorCell.Self, envelope, ActorCell.Self.Equals(receiver) ? "itself" : receiver.ToString());
                _systemMessages.Enqueue(envelope);
            }
            else
            {
                Mailbox.DebugPrint("{0} enqueued message {1} to {2}", ActorCell.Self, envelope, ActorCell.Self.Equals(receiver) ? "itself" : receiver.ToString());
                _userMessages.Enqueue(envelope);
            }

            Schedule();
        }
        /// <summary>
        /// Posts the specified envelope.
        /// </summary>
        /// <param name="receiver"></param>
        /// <param name="envelope"> The envelope. </param>
        public override void Post(IActorRef receiver, Envelope envelope)
        {
            if (_isClosed)
                return;

            hasUnscheduledMessages = true;
            if (envelope.Message is ISystemMessage)
            {
                Mailbox.DebugPrint("{0} enqueued system message {1} to {2}", ActorCell.Self, envelope, ActorCell.Self.Equals(receiver) ? "itself" : receiver.ToString());
                _systemMessages.Enqueue(envelope);
            }
            else
            {
                Mailbox.DebugPrint("{0} enqueued message {1} to {2}", ActorCell.Self, envelope, ActorCell.Self.Equals(receiver) ? "itself" : receiver.ToString());
                _userMessages.Enqueue(envelope);
            }

            Schedule();
        }
Пример #5
0
 /// <summary>
 /// Receive one message of the specified type from the test actor and assert that it
 /// equals the <paramref name="message"/> and was sent by the specified sender
 /// Wait time is bounded by the given duration if specified.
 /// If not specified, wait time is bounded by remaining time for execution of the innermost enclosing 'within'
 /// block, if inside a 'within' block; otherwise by the config value
 /// "akka.test.single-expect-default".
 /// </summary>
 /// <typeparam name="T">TBD</typeparam>
 /// <param name="sender">TBD</param>
 /// <param name="message">TBD</param>
 /// <param name="timeout">TBD</param>
 /// <param name="hint">TBD</param>
 /// <returns>TBD</returns>
 public T ExpectMsgFrom <T>(IActorRef sender, T message, TimeSpan?timeout = null, string hint = null)
 {
     return(InternalExpectMsg <T>(RemainingOrDilated(timeout), m => _assertions.AssertEqual(message, m), s => _assertions.AssertEqual(sender, s, FormatWrongSenderMessage(s, sender.ToString(), hint)), hint));
 }
Пример #6
0
 public override void OnReceive(object message, IActorRef sender)
 {
     UnityEngine.Debug.Log(Thread.CurrentThread.ManagedThreadId + ": received from '" + sender.ToString() + "' the message: " + message.ToString());
     uiManager = uiManager.OrElse(getActorRef(UIManagerPath, system));
     uiManager.ForEach(actor => actor.Tell(new UIMessages.ButtonMessage("LabelBtn")));
 }
Пример #7
0
        public override void OnReceive(object message, IActorRef sender)
        {
            UnityEngine.Debug.Log(Thread.CurrentThread.ManagedThreadId + ": received from '" + sender.ToString() +
                                  "' the message: " + message.ToString());

            switch (message)
            {
            case UIMessages.ButtonMessage button:
                UnityEngine.Debug.LogFormat("button '{0}' is playing", button.name);
                UnityThread.executeInUpdate(() => changeLabelButton(button.name));
                break;

            case UIMessages.SpeedInfo speed:
                UnityEngine.Debug.LogFormat("speedInfo received with '{0}' as value", speed.speed);
                UnityThread.executeInUpdate(() => speedInfo.text = $"{speed.speed:n0} Msg/sec");
                break;

            default:
                UnityEngine.Debug.LogErrorFormat("Unknown message {0}", message);
                break;
            }
        }