Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
            }
        }