Example #1
0
 /// <summary>
 /// This should only be used privately or when creating the root actor.
 /// </summary>
 /// <param name="actor">TBD</param>
 /// <returns>TBD</returns>
 public ChildRestartStats InitChild(IInternalActorRef actor)
 {
     return(UpdateChildrenRefs(cc =>
     {
         IChildStats stats;
         var name = actor.Path.Name;
         if (cc.TryGetByName(name, out stats))
         {
             var old = stats as ChildRestartStats;
             if (old != null)
             {
                 //Do not update. Return old
                 return new Tuple <bool, IChildrenContainer, ChildRestartStats>(false, cc, old);
             }
             if (stats is ChildNameReserved)
             {
                 var crs = new ChildRestartStats(actor);
                 var updatedContainer = cc.Add(name, crs);
                 //Update (if it's still cc) and return the new crs
                 return new Tuple <bool, IChildrenContainer, ChildRestartStats>(true, updatedContainer, crs);
             }
         }
         //Do not update. Return null
         return new Tuple <bool, IChildrenContainer, ChildRestartStats>(false, cc, null);
     }));
 }
Example #2
0
        /// <summary>
        /// This should only be used privately or when creating the root actor.
        /// </summary>
        /// <param name="actor">TBD</param>
        /// <returns>TBD</returns>
        public ChildRestartStats InitChild(IInternalActorRef actor)
        {
            var name = actor.Path.Name;

            while (true)
            {
                var cc = ChildrenContainer;
                if (cc.TryGetByName(name, out var old))
                {
                    switch (old)
                    {
                    case ChildRestartStats restartStats:
                        return(restartStats);

                    case ChildNameReserved _:
                        var crs = new ChildRestartStats(actor);
                        if (SwapChildrenRefs(cc, cc.Add(name, crs)))
                        {
                            return(crs);
                        }
                        break;
                    }
                }
                else
                {
                    return(null);
                }
            }
        }
Example #3
0
        /// <summary>
        ///     This is the main entry point: in case of a child’s failure, this method
        ///     must try to handle the failure by resuming, restarting or stopping the
        ///     child (and returning `true`), or it returns `false` to escalate the
        ///     failure, which will lead to this actor re-throwing the exception which
        ///     caused the failure. The exception will not be wrapped.
        ///     This method calls <see cref="Akka.Actor.SupervisorStrategy"/>, which will
        ///     log the failure unless it is escalated. You can customize the logging by
        ///     setting <see cref="Akka.Actor.SupervisorStrategy" /> to `false` and
        ///     do the logging inside the `decider` or override the `LogFailure` method.
        /// </summary>
        /// <param name="actorCell">The actor cell.</param>
        /// <param name="cause">The cause.</param>
        /// <param name="failedChildStats">The stats for the failed child.</param>
        /// <param name="allChildren"></param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        public bool HandleFailure(ActorCell actorCell, Exception cause, ChildRestartStats failedChildStats, IReadOnlyCollection <ChildRestartStats> allChildren)
        {
            var child     = failedChildStats.Child;
            var directive = Handle(child, cause);

            switch (directive)
            {
            case Directive.Escalate:
                LogFailure(actorCell, child, cause, directive);
                return(false);

            case Directive.Resume:
                LogFailure(actorCell, child, cause, directive);
                ResumeChild(child, cause);
                return(true);

            case Directive.Restart:
                LogFailure(actorCell, child, cause, directive);
                ProcessFailure(actorCell, true, cause, failedChildStats, allChildren);
                return(true);

            case Directive.Stop:
                LogFailure(actorCell, child, cause, directive);
                ProcessFailure(actorCell, false, cause, failedChildStats, allChildren);
                return(true);
            }
            return(false);
        }
Example #4
0
        /// <summary>
        /// Tries to get the stats for the child with the specified name. This ignores children for whom only names have been reserved.
        /// </summary>
        private bool TryGetChildRestartStatsByName(string name, out ChildRestartStats child)
        {
            IChildStats stats;

            if (ChildrenContainer.TryGetByName(name, out stats))
            {
                child = stats as ChildRestartStats;
                if (child != null)
                {
                    return(true);
                }
            }
            child = null;
            return(false);
        }
Example #5
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="actor">TBD</param>
 /// <param name="childRestartStats">TBD</param>
 /// <returns>TBD</returns>
 public bool TryGetByRef(IActorRef actor, out ChildRestartStats childRestartStats)
 {
     if (InternalChildren.TryGetValue(actor.Path.Name, out var 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);
 }
Example #6
0
 protected override void ProcessFailure(IActorContext context, bool restart, IActorRef child, Exception cause, ChildRestartStats stats, IReadOnlyCollection <ChildRestartStats> children)
 {
     TestActor.Tell(new FF(new Failed(child, cause, stats.Uid)), child);
     base.ProcessFailure(context, restart, child, cause, stats, children);
 }
Example #7
0
        protected override void ProcessFailure(IActorContext context, bool restart, Exception cause, ChildRestartStats failedChildStats, IReadOnlyCollection <ChildRestartStats> allChildren)
        {
            if (allChildren.Count > 0)
            {
                var failedChild = failedChildStats.Child;

                if (restart && allChildren.All(c => c.RequestRestartPermission(MaxNumberOfRetries, WithinTimeRangeMilliseconds)))
                {
                    foreach (var crs in allChildren)
                    {
                        RestartChild(crs.Child, cause, suspendFirst: !failedChild.Equals(crs.Child));
                    }
                }
                else
                {
                    foreach (var crs in allChildren)
                    {
                        context.Stop(crs.Child);
                    }
                }
            }
        }
Example #8
0
 public abstract void add(string name, ChildRestartStats stats);
Example #9
0
 /// <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 (restart && stats.RequestRestartPermission(MaxNumberOfRetries, WithinTimeRangeMilliseconds))
     {
         RestartChild(child, cause, suspendFirst: false);
     }
     else
     {
         context.Stop(child);
     }
 }
Example #10
0
 public bool TryGetByRef(ActorRef actor, out ChildRestartStats childRestartStats)
 {
     childRestartStats = null;
     return(false);
 }
Example #11
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="name">TBD</param>
 /// <param name="stats">TBD</param>
 /// <returns>TBD</returns>
 public override IChildrenContainer Add(string name, ChildRestartStats stats)
 {
     return(Create(InternalChildren.SetItem(name, stats)));
 }
Example #12
0
 public bool HandleFailure(ActorCell actorCell, Exception cause, ChildRestartStats failedChildStats, IReadOnlyCollection <ChildRestartStats> allChildren)
 {
     return(HandleFailure(actorCell, failedChildStats.Child, cause, failedChildStats, allChildren));
 }
Example #13
0
        protected override void ProcessFailure(IActorContext context, bool restart, Exception cause, ChildRestartStats failedChildStats, IReadOnlyCollection <ChildRestartStats> allChildren)
        {
            // for compatibility, since 1.1.2

            ProcessFailure(context, restart, failedChildStats.Child, cause, failedChildStats, allChildren);
        }
Example #14
0
 protected override void ProcessFailure(IActorContext context, bool restart, IActorRef child, Exception cause, ChildRestartStats stats,
                                        IReadOnlyCollection <ChildRestartStats> children)
 {
     _logger.Warn($"{cause}");
     base.ProcessFailure(context, restart, child, cause, stats, children);
 }
Example #15
0
            protected override void ProcessFailure(IActorContext context, bool restart, Exception cause, ChildRestartStats failedChildStats, IReadOnlyCollection <ChildRestartStats> allChildren)
            {
                var child = failedChildStats.Child;

                TestActor.Tell(new FF(new Failed(child, cause, failedChildStats.Uid)), child);
                base.ProcessFailure(context, restart, cause, failedChildStats, allChildren);
            }
Example #16
0
 public override void ProcessFailure(IActorContext context, bool restart, IActorRef child, Exception cause, ChildRestartStats stats, IReadOnlyCollection <ChildRestartStats> children)
 => Get(child).ProcessFailure(context, restart, child, cause, stats, children);
Example #17
0
 public override ChildrenContainer Add(string name, ChildRestartStats stats)
 {
     return(Create(InternalChildren.AddOrUpdate(name, stats)));
 }
Example #18
0
        public bool HandleFailure(ActorCell actorCell, Exception cause, ChildRestartStats failedChildStats, IReadOnlyCollection <ChildRestartStats> allChildren)
        {
            // for compatibility, since 1.1.2

            return(HandleFailure(actorCell, failedChildStats.Child, cause, failedChildStats, allChildren));
        }
Example #19
0
 /// <summary>
 /// Tries to get the stats for the specified child.
 /// <remarks>Since the child exists <see cref="ChildRestartStats"/> is the only valid <see cref="IChildStats"/>.</remarks>
 /// </summary>
 /// <param name="actor">TBD</param>
 /// <param name="child">TBD</param>
 /// <returns>TBD</returns>
 protected bool TryGetChildStatsByRef(IActorRef actor, out ChildRestartStats child)   //This is called getChildByRef in Akka JVM
 {
     return(ChildrenContainer.TryGetByRef(actor, out child));
 }
 public override IChildrenContainer Add(string name, ChildRestartStats stats)
 {
     return(this);
 }
Example #21
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="name">TBD</param>
 /// <param name="stats">TBD</param>
 /// <returns>TBD</returns>
 public abstract IChildrenContainer Add(string name, ChildRestartStats stats);
        public override IChildrenContainer Add(string name, ChildRestartStats stats)
        {
            var newMap = InternalChildren.SetItem(name, stats);

            return(new TerminatingChildrenContainer(newMap, _toDie, _reason));
        }
Example #23
0
        public virtual ChildrenContainer Add(string name, ChildRestartStats stats)
        {
            var newMap = _emptyStats.Add(name, stats);

            return(NormalChildrenContainer.Create(newMap));
        }
Example #24
0
 /// <summary>
 /// This method is called to act on the failure of a child: restart if the flag is true, stop otherwise.
 /// </summary>
 /// <param name="context">The actor context.</param>
 /// <param name="restart">if set to <c>true</c> restart, stop otherwise.</param>
 /// <param name="cause">The exception that caused the child to fail.</param>
 /// <param name="failedChildStats">The stats for the child that failed. The ActorRef to the child can be obtained via the <see cref="ChildRestartStats.Child"/> property</param>
 /// <param name="allChildren">The stats for all children</param>
 protected abstract void ProcessFailure(IActorContext context, bool restart, Exception cause, ChildRestartStats failedChildStats, IReadOnlyCollection <ChildRestartStats> allChildren);
Example #25
0
 /// <summary>
 /// This method is called to act on the failure of a child: restart if the flag is true, stop otherwise.
 /// </summary>
 /// <param name="context">The actor context.</param>
 /// <param name="restart">if set to <c>true</c> restart, stop otherwise.</param>
 /// <param name="child">The child actor</param>
 /// <param name="cause">The exception that caused the child to fail.</param>
 /// <param name="stats">The stats for the child that failed. The ActorRef to the child can be obtained via the <see cref="ChildRestartStats.Child"/> property</param>
 /// <param name="children">The stats for all children</param>
 public abstract void ProcessFailure(IActorContext context, bool restart, IActorRef child, Exception cause, ChildRestartStats stats, IReadOnlyCollection <ChildRestartStats> children);
Example #26
0
        protected override void ProcessFailure(IActorContext context, bool restart, Exception cause, ChildRestartStats failedChildStats, IReadOnlyCollection <ChildRestartStats> allChildren)
        {
            var failedChild = failedChildStats.Child;

            if (restart && failedChildStats.RequestRestartPermission(MaxNumberOfRetries, WithinTimeRangeMilliseconds))
            {
                RestartChild(failedChild, cause, suspendFirst: false);
            }
            else
            {
                context.Stop(failedChild);
            }
        }
Example #27
0
 /// <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);
             }
         }
     }
 }
 public abstract void add(string name, ChildRestartStats stats);