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); } }
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.cluster = cluster.IfNoneUnsafe(() => null); this.maxMailboxSize = maxMailboxSize == -1 ? ActorContext.System(actor.Id).Settings.GetProcessMailboxSize(actor.Id) : maxMailboxSize; this.parent = parent; userNotify = new PausableBlockingQueue <string>(this.maxMailboxSize); var obj = new ThreadObj { Actor = actor, Inbox = this, Parent = parent }; userNotify.ReceiveAsync(obj, (state, msg) => { CheckRemoteInbox(ActorInboxCommon.ClusterUserInboxKey(state.Actor.Id), true); return(InboxDirective.Default); }); SubscribeToSysInboxChannel(); SubscribeToUserInboxChannel(); this.cluster.SetValue(ActorInboxCommon.ClusterMetaDataKey(actor.Id), new ProcessMetaData( new[] { typeof(T).AssemblyQualifiedName }, typeof(S).AssemblyQualifiedName, typeof(S).GetTypeInfo().ImplementedInterfaces.Map(x => x.AssemblyQualifiedName).ToArray() )); return(unit); }
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 void Dispose() { userInbox?.Cancel(); sysInbox?.Cancel(); userInbox = null; sysInbox = null; }
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); }
/// <exception cref="System.Exception"></exception> public virtual void TestDrainTo() { IPausableBlockingQueue4 queue = new PausableBlockingQueue(); queue.Add(new object()); queue.Add(new object()); queue.Pause(); Collection4 list = new Collection4(); Thread t = ExecuteAfter("Pausable queue drainer", 0, new _IRunnable_66(queue, list )); Runtime4.SleepThrowsOnInterrupt(200); lock (list) { Assert.AreEqual(0, list.Size()); } Assert.IsTrue(queue.HasNext()); queue.Resume(); t.Join(); lock (list) { Assert.AreEqual(2, list.Size()); } Assert.IsFalse(queue.HasNext()); }
public virtual void TestStop() { IPausableBlockingQueue4 queue = new PausableBlockingQueue(); queue.Pause(); ExecuteAfter("Pausable queue stopper", 200, new _IRunnable_40(queue)); Assert.Expect(typeof(BlockingQueueStoppedException), new _ICodeBlock_46(queue)); }
public Unit Shutdown() { userInbox?.Cancel(); sysInbox?.Cancel(); userInbox = null; sysInbox = null; return(unit); }
public void Dispose() { userInbox?.Cancel(); sysInbox?.Cancel(); cluster?.UnsubscribeChannel(ActorInboxCommon.ClusterUserInboxNotifyKey(actor.Id)); cluster?.UnsubscribeChannel(ActorInboxCommon.ClusterSystemInboxNotifyKey(actor.Id)); userInbox = null; sysInbox = null; cluster = null; }
public virtual void TestTimeoutNext() { IPausableBlockingQueue4 queue = new PausableBlockingQueue(); Assert.IsFalse(queue.IsPaused()); queue.Pause(); Assert.IsTrue(queue.IsPaused()); object obj = new object(); queue.Add(obj); Assert.IsTrue(queue.HasNext()); Assert.IsNull(queue.TryNext()); queue.Resume(); Assert.AreSame(obj, queue.Next(50)); }
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})"); } }
public _IClosure4_46(PausableBlockingQueue _enclosing) { this._enclosing = _enclosing; }