private string GetNameBy(IActorRef sender) { foreach (var item in _members.Where(item => item.Value.Equals(sender))) { return item.Key; } return sender.Equals(Self) ? "The Room" : string.Empty; }
void RemoveActiveProcessor(IActorRef aRef) { foreach (var kvp in _processors) { if (aRef.Equals(kvp.Value)) { _processors.Remove(kvp.Key); return; } } }
bool RemoveActiveProcessor(IActorRef aRef) { foreach (var kvp in _aggregates) { if (aRef.Equals(kvp.Value)) { _aggregates.Remove(kvp.Key); return true; } } return false; }
/// <summary> /// Processor for messages that are sent to the root system guardian /// </summary> /// <param name="message">TBD</param> /// <returns>TBD</returns> protected override bool Receive(object message) { var terminated = message as Terminated; if (terminated != null) { var terminatedActor = terminated.ActorRef; if (_userGuardian.Equals(terminatedActor)) { // time for the systemGuardian to stop, but first notify all the // termination hooks, they will reply with TerminationHookDone // and when all are done the systemGuardian is stopped Context.Become(Terminating); foreach (var terminationHook in _terminationHooks) { terminationHook.Tell(TerminationHook.Instance); } StopWhenAllTerminationHooksDone(); } else { // a registered, and watched termination hook terminated before // termination process of guardian has started _terminationHooks.Remove(terminatedActor); } return(true); } var stopChild = message as StopChild; if (stopChild != null) { Context.Stop(stopChild.Child); return(true); } var sender = Sender; var registerTerminationHook = message as RegisterTerminationHook; if (registerTerminationHook != null && !ReferenceEquals(sender, Context.System.DeadLetters)) { _terminationHooks.Add(sender); Context.Watch(sender); return(true); } Context.System.DeadLetters.Tell(new DeadLetter(message, sender, Self), sender); return(true); }
public bool TryGetByRef(IActorRef actor, out ChildRestartStats childRestartStats) { IChildStats stats; if (InternalChildren.TryGet(actor.Path.Name, out stats)) { //Since the actor exists, ChildRestartStats is the only valid ChildStats. var crStats = stats as ChildRestartStats; if (crStats != null && actor.Equals(crStats.Child)) { childRestartStats = crStats; return true; } } childRestartStats = null; return false; }
/// <inheritdoc/> public override bool Equals(object obj) { var other = obj as ShardHomeAllocated; if (ReferenceEquals(other, null)) { return(false); } if (ReferenceEquals(other, this)) { return(true); } return(Shard.Equals(other.Shard) && Region.Equals(other.Region)); }
public bool TryGetByRef(IActorRef actor, out ChildRestartStats childRestartStats) { IChildStats stats; if (InternalChildren.TryGetValue(actor.Path.Name, out stats)) { //Since the actor exists, ChildRestartStats is the only valid ChildStats. var crStats = stats as ChildRestartStats; if (crStats != null && actor.Equals(crStats.Child)) { childRestartStats = crStats; return(true); } } childRestartStats = null; return(false); }
private void HandleTerminated(Terminated terminated) { IImmutableSet <ShardId> shards; ShardId shard; if (_coordinator != null && _coordinator.Equals(terminated.ActorRef)) { _coordinator = null; } else if (Regions.TryGetValue(terminated.ActorRef, out shards)) { RegionByShard = RegionByShard.RemoveRange(shards); Regions = Regions.Remove(terminated.ActorRef); if (Log.IsDebugEnabled) { Log.Debug("Region [{0}] with shards [{1}] terminated", terminated.ActorRef, string.Join(", ", shards)); } } else if (ShardsByRef.TryGetValue(terminated.ActorRef, out shard)) { ShardsByRef = ShardsByRef.Remove(terminated.ActorRef); Shards = Shards.Remove(shard); //Are we meant to be handing off, or is this a unknown stop? if (HandingOff.Contains(terminated.ActorRef)) { HandingOff = HandingOff.Remove(terminated.ActorRef); Log.Debug("Shard [{0}] handoff complete", shard); } else { // if persist fails it will stop Log.Debug("Shard [{0}] terminated while not being handed off", shard); if (Settings.RememberEntities) { Context.System.Scheduler.ScheduleTellOnce(Settings.TunningParameters.ShardFailureBackoff, Self, new RestartShard(shard), Self); } } TryCompleteGracefulShutdown(); } }
/// <summary> /// TBD /// </summary> /// <param name="context">TBD</param> /// <param name="restart">TBD</param> /// <param name="child">TBD</param> /// <param name="cause">TBD</param> /// <param name="stats">TBD</param> /// <param name="children">TBD</param> public override void ProcessFailure(IActorContext context, bool restart, IActorRef child, Exception cause, ChildRestartStats stats, IReadOnlyCollection <ChildRestartStats> children) { if (children.Count > 0) { if (restart && children.All(c => c.RequestRestartPermission(MaxNumberOfRetries, WithinTimeRangeMilliseconds))) { foreach (var crs in children) { RestartChild(crs.Child, cause, suspendFirst: !child.Equals(crs.Child)); } } else { foreach (var crs in children) { context.Stop(crs.Child); } } } }
private void Handle(ClusterActorDiscoveryMessage.ActorDown m) { _log.Info($"Table.ActorDown (Actor={m.Actor.Path})"); if (_table.Equals(m.Actor) == false) { _log.Error($"But I have a different table. (Actor={_table.Path})"); return; } _table = null; CancelAllPendingAddRequests(); foreach (var i in _actorMap) { i.Value.Tell(_downMessage ?? PoisonPill.Instance); } // NOTE: should we clear actor map or let them to be removed ? }
protected void HandleMsg(object message, IActorRef sender = null) { sender = sender ?? Sender; if (CheckIsEvent(message)) { var confirmable = DoMakeEventConfirmable(message, ++_currentDeliveryId); _eventBuffer[confirmable.ConfirmationId] = new PersistentEvent(confirmable, Sender); Child.Tell(confirmable, sender); } else if (message is Confirmation confirmation) { if (Log.IsDebugEnabled) { Log.Debug("Confirming delivery of event [{0}] from [{1}]", confirmation.ConfirmationId, confirmation.SenderId); } if (!_eventBuffer.Remove(confirmation.ConfirmationId)) { Log.Warning("Received confirmation for unknown event [{0}] from persistent entity [{1}]", confirmation.ConfirmationId, confirmation.SenderId); } } else if (sender.Equals(Child)) { // use the BackoffSupervisor as sender Context.Parent.Tell(message); } else { Child.Tell(message, sender); if (!FinalStopMessageReceived && FinalStopMessage != null) { FinalStopMessageReceived = FinalStopMessage(message); } } }
protected override void OnReceive(object message) { if (message is Terminated) { var terminated = (Terminated)message; if (_child != null && _child.Equals(terminated.ActorRef)) { _child = null; var rand = 1.0 + ThreadLocalRandom.Current.NextDouble() * _randomFactor; TimeSpan restartDelay; if (_restartCount >= 30) { restartDelay = _maxBackoff; // duration overflow protection (> 100 years) } else { var max = Math.Min(_maxBackoff.Ticks, _minBackoff.Ticks * Math.Pow(2, _restartCount)) * rand; if (max >= Double.MaxValue) { restartDelay = _maxBackoff; } else { restartDelay = new TimeSpan((long)max); } } Context.System.Scheduler.ScheduleTellOnce(restartDelay, Self, StartChild.Instance, Self); _restartCount++; } else { Unhandled(message); } } else if (message is StartChild) { StartChildActor(); Context.System.Scheduler.ScheduleTellOnce(_minBackoff, Self, new ResetRestartCount(_restartCount), Self); } else if (message is ResetRestartCount) { var restartCount = (ResetRestartCount)message; if (restartCount.Current == _restartCount) { _restartCount = 0; } } else if (message is GetCurrentChild) { Sender.Tell(new CurrentChild(_child)); } else { if (_child != null) { _child.Forward(message); } else { Context.System.DeadLetters.Forward(message); } } }
private Receive Active(IActorRef receptionist) { return(message => { if (message is Send send) { receptionist.Forward(new PublishSubscribe.Send(send.Path, send.Message, send.LocalAffinity)); } else if (message is SendToAll sendToAll) { receptionist.Forward(new PublishSubscribe.SendToAll(sendToAll.Path, sendToAll.Message)); } else if (message is Publish publish) { receptionist.Forward(new PublishSubscribe.Publish(publish.Topic, publish.Message)); } else if (message is HeartbeatTick) { if (!_failureDetector.IsAvailable) { _log.Info("Lost contact with [{0}], reestablishing connection", receptionist); Reestablish(); } else { receptionist.Tell(ClusterReceptionist.Heartbeat.Instance); } } else if (message is ClusterReceptionist.HeartbeatRsp) { _failureDetector.HeartBeat(); } else if (message is RefreshContactsTick) { receptionist.Tell(ClusterReceptionist.GetContacts.Instance); } else if (message is ClusterReceptionist.Contacts contacts) { // refresh of contacts if (contacts.ContactPoints.Count > 0) { _contactPaths = contacts.ContactPoints.Select(ActorPath.Parse).ToImmutableHashSet(); _contacts = _contactPaths.Select(Context.ActorSelection).ToArray(); } PublishContactPoints(); } else if (message is ActorIdentity) { // ok, from previous establish, already handled } else if (message is ClusterReceptionist.ReceptionistShutdown) { if (receptionist.Equals(Sender)) { _log.Info("Receptionist [{0}] is shutting down, reestablishing connection", receptionist); Reestablish(); } } else { return ContactPointMessages(message); } return true; }); }
/// <summary> /// Determine if a <see cref="Watch"/>/<see cref="Unwatch"/> message must be handled by the <see cref="RemoteWatcher"/> /// actor, or sent to this <see cref="RemoteActorRef"/>. /// </summary> /// <param name="watchee">The actor being watched.</param> /// <param name="watcher">The actor watching.</param> /// <returns>TBD</returns> public bool IsWatchIntercepted(IActorRef watchee, IActorRef watcher) { return(!watcher.Equals(RemoteProvider.RemoteWatcher) && watchee.Equals(this)); }
/// <summary> /// Determine if a <see cref="Watch"/>/<see cref="Unwatch"/> message must be handled by the <see cref="RemoteWatcher"/> /// actor, or sent to this <see cref="RemoteActorRef"/>. /// </summary> /// <param name="watchee">The actor being watched.</param> /// <param name="watcher">The actor watching.</param> /// <returns></returns> public bool IsWatchIntercepted(IActorRef watchee, IActorRef watcher) { return !watcher.Equals(RemoteProvider.RemoteWatcher) && watchee.Equals(this); }
private static bool GetChild(string name, out IActorRef actor) { actor = Context.Child(name); return(actor.Equals(ActorRefs.Nobody)); }
public bool Equals(IActorRef other) { return(_wrappedRef.Equals(other)); }
private void SendTerminated(bool ifLocal, IActorRef watcher) { if (((IActorRefScope)watcher).IsLocal == ifLocal && !watcher.Equals(Parent)) { watcher.Tell(new DeathWatchNotification(Self, true, false)); } }
protected void RemWatcher(IActorRef watchee, IActorRef watcher) { var watcheeSelf = watchee.Equals(Self); var watcherSelf = watcher.Equals(Self); if (watcheeSelf && !watcherSelf) { if (_state.ContainsWatchedBy(watcher)) MaintainAddressTerminatedSubscription(() => { //_watchedBy.Remove(watcher); _state = _state.RemoveWatchedBy(watcher); if (System.Settings.DebugLifecycle) Publish(new Debug(Self.Path.ToString(), Actor.GetType(), string.Format("no longer watched by {0}", watcher))); }, watcher); } else if (!watcheeSelf && watcherSelf) { Unwatch(watchee); } else { Publish(new Warning(Self.Path.ToString(), Actor.GetType(), string.Format("BUG: illegal Unwatch({0},{1} for {2}", watchee, watcher, Self))); } }
public bool Equals(IActorRef other) { return(_delegate.Equals(other)); }