public Unit Startup(IActor process, ActorItem parent, Option <ICluster> cluster, int maxMailboxSize) { if (cluster.IsNone) { throw new Exception("Remote inboxes not supported when there's no cluster"); } this.actor = (Actor <S, T>)process; this.parent = parent; this.cluster = cluster.IfNoneUnsafe(() => null); this.maxMailboxSize = maxMailboxSize == -1 ? ActorContext.System(actor.Id).Settings.GetProcessMailboxSize(actor.Id) : maxMailboxSize; userInbox = new PausableBlockingQueue <UserControlMessage>(this.maxMailboxSize); sysInbox = new PausableBlockingQueue <SystemMessage>(this.maxMailboxSize); var obj = new ThreadObj { Actor = actor, Inbox = this, Parent = parent }; userInbox.ReceiveAsync(obj, (state, msg) => ActorInboxCommon.UserMessageInbox(state.Actor, state.Inbox, msg, state.Parent)); sysInbox.ReceiveAsync(obj, (state, msg) => ActorInboxCommon.SystemMessageInbox(state.Actor, state.Inbox, msg, state.Parent)); SubscribeToSysInboxChannel(); SubscribeToUserInboxChannel(); return(unit); }
public Unit Startup(IActor process, ActorItem parent, Option <ICluster> cluster, int maxMailboxSize) { if (Active) { Shutdown(); } this.cluster = cluster; this.parent = parent; this.actor = (Actor <S, T>)process; this.maxMailboxSize = maxMailboxSize == -1 ? ActorContext.System(actor.Id).Settings.GetProcessMailboxSize(actor.Id) : maxMailboxSize; userInbox = new PausableBlockingQueue <UserControlMessage>(this.maxMailboxSize); sysInbox = new PausableBlockingQueue <SystemMessage>(this.maxMailboxSize); var obj = new ThreadObj { Actor = actor, Inbox = this, Parent = parent }; userInbox.ReceiveAsync(obj, (state, msg) => ActorInboxCommon.UserMessageInbox(state.Actor, state.Inbox, msg, state.Parent)); sysInbox.ReceiveAsync(obj, (state, msg) => ActorInboxCommon.SystemMessageInbox(state.Actor, state.Inbox, msg, state.Parent)); return(unit); }
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--; } } }