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) => process.CancellationTokenSource.IsCancellationRequested ? InboxDirective.Shutdown : 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); }
/// <summary> /// TODO: This is a combination of code in ActorCommon.GetNextMessage and /// CheckRemoteInbox. Some factoring is needed. /// </summary> void SysInbox(RemoteMessageDTO dto) { try { if (dto == null) { // Failed to deserialise properly return; } if (dto.Tag == 0 && dto.Type == 0) { // Message is bad tell(ActorContext.System(actor.Id).DeadLetters, DeadLetter.create(dto.Sender, actor.Id, null, "Failed to deserialise message: ", dto)); return; } var msg = MessageSerialiser.DeserialiseMsg(dto, actor.Id); try { lock (sync) { ActorInboxCommon.SystemMessageInbox(actor, this, (SystemMessage)msg, parent); } } catch (Exception e) { var session = msg.SessionId == null ? None : Some(new SessionId(msg.SessionId)); ActorContext.System(actor.Id).WithContext(new ActorItem(actor, this, 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); } } catch (Exception e) { logSysErr(e); } }