protected override void EntityTerminated(IActorRef tref) { ShardId id; IImmutableList <Tuple <Msg, IActorRef> > buffer; if (IdByRef.TryGetValue(tref, out id)) { if (MessageBuffers.TryGetValue(id, out buffer) && buffer.Count != 0) { // Note; because we're not persisting the EntityStopped, we don't need // to persist the EntityStarted either. Log.Debug("Starting entity [{0}] again, there are buffered messages for it", id); SendMessageBuffer(new EntityStarted(id)); } else { if (!Passivating.Contains(tref)) { Log.Debug("Entity [{0}] stopped without passivating, will restart after backoff", id); Context.System.Scheduler.ScheduleTellOnce(Settings.TunningParameters.EntityRestartBackoff, Sender, new RestartEntity(id), Self); } else { ProcessChange(new EntityStopped(id), PassivateCompleted); } } } Passivating = Passivating.Remove(tref); }
public void DeliverTo(string id, object message, object payload, IActorRef sender) { var name = Uri.EscapeDataString(id); var child = Context.Child(name); if (Equals(child, ActorRefs.Nobody)) { if (State.Entries.Contains(id)) { if (MessageBuffers.ContainsKey(id)) { throw new InvalidOperationException($"Message buffers contains id [{id}]."); } this.GetEntity(id).Tell(payload, sender); } else { // Note; we only do this if remembering, otherwise the buffer is an overhead MessageBuffers = MessageBuffers.SetItem(id, ImmutableList <Tuple <object, IActorRef> > .Empty.Add(Tuple.Create(message, sender))); ProcessChange(new Shard.EntityStarted(id), this.SendMessageBuffer); } } else { child.Tell(payload, sender); } }
public void EntityTerminated(IActorRef tref) { if (IdByRef.TryGetValue(tref, out var id)) { IdByRef = IdByRef.Remove(tref); RefById = RefById.Remove(id); if (MessageBuffers.TryGetValue(id, out var buffer) && buffer.Count != 0) { //Note; because we're not persisting the EntityStopped, we don't need // to persist the EntityStarted either. Log.Debug("Starting entity [{0}] again, there are buffered messages for it", id); this.SendMessageBuffer(new Shard.EntityStarted(id)); } else { if (!Passivating.Contains(tref)) { Log.Debug("Entity [{0}] stopped without passivating, will restart after backoff", id); Context.System.Scheduler.ScheduleTellOnce(Settings.TunningParameters.EntityRestartBackoff, Self, new Shard.RestartEntity(id), ActorRefs.NoSender); } else { ProcessChange(new Shard.EntityStopped(id), this.PassivateCompleted); } } Passivating = Passivating.Remove(tref); } }
/// <summary> /// TBD /// </summary> /// <param name="id">TBD</param> /// <param name="message">TBD</param> /// <param name="payload">TBD</param> /// <param name="sender">TBD</param> /// <returns>TBD</returns> protected override void DeliverTo(string id, object message, object payload, IActorRef sender) { var name = Uri.EscapeDataString(id); var child = _context.Child(name); if (Equals(child, ActorRefs.Nobody)) { // Note; we only do this if remembering, otherwise the buffer is an overhead MessageBuffers = MessageBuffers.SetItem(id, ImmutableList <Tuple <object, IActorRef> > .Empty.Add(Tuple.Create(message, sender))); ProcessChange(new EntityStarted(id), SendMessageBuffer); } else { child.Tell(payload, sender); } }
protected SocketCarSignalSeedV4(IMessenger messenger) { Buffer = new MessageBuffers(); Logger = LogManager.GetLogger(GetType()); }