Пример #1
0
        public void Dispatch(int budgetMs)
        {
            Stopwatch sw = Stopwatch.StartNew();

            //Console.WriteLine($"Dispatch: {milliseconds} ms");
            while (sw.ElapsedMilliseconds < budgetMs)
            {
                //Console.WriteLine($"Elapsed: {sw.ElapsedMilliseconds}");
                // read system messages and send to destination mailboxes
                var msg = SystemBus.Dequeue();
                // TODO: messagebus is still primitive. We need to check for null!
                if (msg != null)
                {
                    // look up destination actor instance
                    var registration = Registry.Find(msg.To);
                    var destination  = registration.Address;
                    if (destination.IsRemote)
                    {
                        // TODO: route to remote destination

                        continue;
                    }

                    var actor = Registry.FindActor(registration.Id);
                    actor.TellSystem(msg);
                }
                else
                {
                    break;
                }
            }

            while (sw.ElapsedMilliseconds < budgetMs)
            {
                // read remaining messages and send to destination mailboxes
                var msg = MessageBus.Dequeue();
                // TODO: messagebus is still primitive. We need to check for null!
                if (msg != null)
                {
                    // look up destination actor instance
                    var registration = Registry.Find(msg.To);
                    var destination  = registration.Address;
                    if (destination.IsRemote)
                    {
                        // TODO: route to remote destination

                        continue;
                    }

                    var actor = Registry.FindActor(registration.Id);
                    actor.Tell(msg);
                }
                else
                {
                    break;
                }
            }
        }