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); } }
void CheckRemoteInbox(string key, bool pausable) { var inbox = this; var count = cluster?.QueueLength(key) ?? 0; while (count > 0 && (!pausable || !IsPaused)) { var directive = InboxDirective.Default; ActorInboxCommon.GetNextMessage(cluster, actor.Id, key).IfSome( x => iter(x, (dto, msg) => { try { switch (msg.MessageType) { case Message.Type.User: directive = ActorInboxCommon.UserMessageInbox(actor, inbox, (UserControlMessage)msg, parent); break; case Message.Type.UserControl: directive = ActorInboxCommon.UserMessageInbox(actor, inbox, (UserControlMessage)msg, parent); break; } } catch (Exception e) { var session = msg.SessionId == null ? None : Some(new SessionId(msg.SessionId)); ActorContext.System(actor.Id).WithContext(new ActorItem(actor, inbox, actor.Flags), parent, dto.Sender, msg as ActorRequest, msg, session, () => replyErrorIfAsked(e)); tell(ActorContext.System(actor.Id).DeadLetters, DeadLetter.create(dto.Sender, actor.Id, e, "Remote message inbox.", msg)); logSysErr(e); } finally { if ((directive & InboxDirective.Pause) != 0) { IsPaused = true; directive = directive & (~InboxDirective.Pause); } if (directive == InboxDirective.Default) { cluster?.Dequeue <RemoteMessageDTO>(key); } } })); if (directive == InboxDirective.Default) { count--; } } }