diff --git a/src/core/Akka/Actor/ActorCell.Children.cs b/src/core/Akka/Actor/ActorCell.Children.cs
index afa28dee6b8..1dcf57b5fcb 100644
--- a/src/core/Akka/Actor/ActorCell.Children.cs
+++ b/src/core/Akka/Actor/ActorCell.Children.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Threading;
using Akka.Actor.Internal;
using Akka.Util;
@@ -10,6 +11,7 @@ namespace Akka.Actor
public partial class ActorCell
{
private ChildrenContainer _childrenContainerDoNotCallMeDirectly = EmptyChildrenContainer.Instance;
+ private long _nextRandomNameDoNotCallMeDirectly;
[Obsolete("Use ChildrenContainer instead", true)]
private ChildrenContainer ChildrenRefs
@@ -58,16 +60,11 @@ private ActorRef ActorOf(Props props, string name, bool isAsync, bool isSystemSe
if (name == null)
name = GetRandomActorName();
else
- {
CheckName(name);
- }
return MakeChild(props, name, isAsync, isSystemService);
}
-
-
- private long _nextRandomNameDoNotCallMeDirectly;
-
+
private string GetRandomActorName()
{
var id = Interlocked.Increment(ref _nextRandomNameDoNotCallMeDirectly);
@@ -110,7 +107,7 @@ private void SwapChildrenRefs() { }
/// The third value of the tuple that returned.
private TReturn UpdateChildrenRefs(Func> updater)
{
- return InterlockedSpin.ConditionallySwap(ref _childrenContainerDoNotCallMeDirectly, updater);
+ return InterlockedSpin.ConditionallySwap(ref _childrenContainerDoNotCallMeDirectly, updater);
}
///
@@ -140,7 +137,7 @@ protected void UnreserveChild(string name)
/// This should only be used privately or when creating the root actor.
public ChildRestartStats InitChild(InternalActorRef actor)
{
- return UpdateChildrenRefs(cc =>
+ return UpdateChildrenRefs(cc =>
{
ChildStats stats;
var name = actor.Path.Name;
@@ -167,14 +164,13 @@ public ChildRestartStats InitChild(InternalActorRef actor)
protected bool SetChildrenTerminationReason(SuspendReason reason)
{
- return UpdateChildrenRefs(cc =>
+ return UpdateChildrenRefs(cc =>
{
var c = cc as TerminatingChildrenContainer;
if (c != null)
- {
//The arguments says: Update; with a new reason; and return true
return new Tuple(true, c.CreateCopyWithReason(reason), true);
- }
+
//The arguments says:Do NOT update; any container will do since it wont be updated; return false
return new Tuple(false, cc, false);
});
@@ -202,23 +198,12 @@ protected void SetTerminated()
///
private void SuspendChildren(List exceptFor = null)
{
- if (exceptFor == null)
- {
- foreach (var stats in ChildrenContainer.Stats)
- {
- var child = stats.Child;
- child.Suspend();
- }
- }
- else
- {
- foreach (var stats in ChildrenContainer.Stats)
- {
- var child = stats.Child;
- if (!exceptFor.Contains(child))
- child.Suspend();
- }
- }
+ var except = exceptFor ?? Enumerable.Empty();
+ (from s in ChildrenContainer.Stats
+ where !except.Contains(s.Child)
+ select s.Child)
+ .ToList()
+ .ForEach(c => c.Suspend());
}
///
@@ -254,9 +239,7 @@ private bool TryGetChildRestartStatsByName(string name, out ChildRestartStats ch
{
child = stats as ChildRestartStats;
if (child != null)
- {
return true;
- }
}
child = null;
return false;