Beispiel #1
0
        public void CheckRemoteInbox(string key, ICluster cluster, ProcessId self, PausableBlockingQueue <SystemMessage> sysInbox, PausableBlockingQueue <UserControlMessage> userInbox, bool pausable)
        {
            try
            {
                int count = cluster.QueueLength(key);

                while (count > 0 && (!pausable || !IsPaused))
                {
                    Option <Tuple <RemoteMessageDTO, Message> > pair;
                    lock (sync)
                    {
                        pair = ActorInboxCommon.GetNextMessage(cluster, self, key);
                        pair.IfSome(x => cluster.Dequeue <RemoteMessageDTO>(key));
                    }

                    pair.IfSome(x => iter(x, (dto, msg) =>
                    {
                        switch (msg.MessageType)
                        {
                        case Message.Type.System: sysInbox.Post((SystemMessage)msg); break;

                        case Message.Type.User: userInbox.Post((UserControlMessage)msg); break;

                        case Message.Type.UserControl: userInbox.Post((UserControlMessage)msg); break;
                        }
                    }));
                    count--;
                }
            }
            catch (Exception e)
            {
                logSysErr($"CheckRemoteInbox failed for {self}", e);
            }
        }
Beispiel #2
0
 public Unit Ask(object message, ProcessId sender, Option <SessionId> sessionId)
 {
     if (userInbox != null)
     {
         ActorInboxCommon.PreProcessMessage <T>(sender, actor.Id, message, sessionId)
         .IfSome(msg =>
         {
             if (IsPaused)
             {
                 new ActorDispatchRemote(ActorContext.System(actor.Id).Ping, actor.Id, cluster, ActorContext.SessionId, false).Ask(message, sender);
             }
             else
             {
                 try
                 {
                     userInbox?.Post(msg);
                 }
                 catch (QueueFullException)
                 {
                     throw new ProcessInboxFullException(actor.Id, MailboxSize, "user");
                 }
             }
         });
     }
     return(unit);
 }
 public Unit Ask(object message, ProcessId sender, Option <SessionId> sessionId)
 {
     if (message == null)
     {
         throw new ArgumentNullException(nameof(message));
     }
     if (userInbox != null)
     {
         try
         {
             return(ActorInboxCommon.PreProcessMessage <T>(sender, actor.Id, message, sessionId)
                    .IfSome(msg => userInbox?.Post(msg)));
         }
         catch (QueueFullException)
         {
             throw new ProcessInboxFullException(actor.Id, MailboxSize, "user");
         }
     }
     return(unit);
 }
Beispiel #4
0
 public Unit TellSystem(SystemMessage message)
 {
     if (message == null)
     {
         throw new ArgumentNullException(nameof(message));
     }
     if (sysInbox != null)
     {
         try
         {
             sysInbox?.Post(message);
         }
         catch (QueueFullException)
         {
             throw new ProcessInboxFullException(actor.Id, MailboxSize, "system");
         }
     }
     return(unit);
 }
        public void TestTypes()
        {
            var errors = Seq <ProcessLogItem>();

            Process.ProcessSystemLog
            .Where(log => log.Type > ProcessLogItemType.Warning)
            .Subscribe(log => errors = log.Cons(errors));

            var queue = new PausableBlockingQueue <int>(10000);

            const int max = 1000;

            using (queue.ReceiveAsync(0, (s, m) => { count++; return(InboxDirective.Default); }))
            {
                Range(0, max).Iter(i => queue.Post(i));

                Thread.Sleep(1000);

                Assert.True(count == max, $"Should be {max} is actually {count} (errors: {errors.Count})");
            }
        }
Beispiel #6
0
 void SubscribeToUserInboxChannel()
 {
     cluster.UnsubscribeChannel(ActorInboxCommon.ClusterUserInboxNotifyKey(actor.Id));
     cluster.SubscribeToChannel <string>(ActorInboxCommon.ClusterUserInboxNotifyKey(actor.Id)).Subscribe(msg => userNotify.Post(msg));
     // We want the check done asyncronously, in case the setup function creates child processes that
     // won't exist if we invoke directly.
     cluster.PublishToChannel(ActorInboxCommon.ClusterUserInboxNotifyKey(actor.Id), Guid.NewGuid().ToString());
 }