Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PrintTree method to ExtendedActorSystem #5858

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/core/Akka.API.Tests/CoreAPISpec.ApproveCore.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ namespace Akka.Actor
{
public const int UndefinedUid = 0;
public ActorCell(Akka.Actor.Internal.ActorSystemImpl system, Akka.Actor.IInternalActorRef self, Akka.Actor.Props props, Akka.Dispatch.MessageDispatcher dispatcher, Akka.Actor.IInternalActorRef parent) { }
protected Akka.Actor.ActorBase Actor { get; }
public Akka.Actor.Internal.IChildrenContainer ChildrenContainer { get; }
public int CurrentEnvelopeId { get; }
public object CurrentMessage { get; }
Expand Down Expand Up @@ -709,6 +708,7 @@ namespace Akka.Actor
public abstract Akka.Actor.IActorRefProvider Provider { get; }
public abstract Akka.Actor.IInternalActorRef SystemGuardian { get; }
public abstract void Abort();
public abstract string PrintTree();
public abstract Akka.Actor.IActorRef SystemActorOf(Akka.Actor.Props props, string name = null);
public abstract Akka.Actor.IActorRef SystemActorOf<TActor>(string name = null)
where TActor : Akka.Actor.ActorBase, new ();
Expand Down Expand Up @@ -1941,6 +1941,7 @@ namespace Akka.Actor.Internal
public override bool HasExtension(System.Type type) { }
public override bool HasExtension<T>()
where T : class, Akka.Actor.IExtension { }
public override string PrintTree() { }
public override object RegisterExtension(Akka.Actor.IExtensionId extension) { }
public override void RegisterOnTermination(System.Action code) { }
public void Start() { }
Expand Down Expand Up @@ -2091,6 +2092,7 @@ namespace Akka.Actor.Internal
public override bool IsNormal { get; }
public override bool IsTerminating { get; }
public Akka.Actor.Internal.SuspendReason Reason { get; }
public System.Collections.Immutable.ImmutableHashSet<Akka.Actor.IActorRef> ToDie { get; }
public override Akka.Actor.Internal.IChildrenContainer Add(string name, Akka.Actor.Internal.ChildRestartStats stats) { }
public Akka.Actor.Internal.IChildrenContainer CreateCopyWithReason(Akka.Actor.Internal.SuspendReason reason) { }
public override Akka.Actor.Internal.IChildrenContainer Remove(Akka.Actor.IActorRef child) { }
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Actor/ActorCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public ActorCell(ActorSystemImpl system, IInternalActorRef self, Props props, Me
/// <summary>
/// TBD
/// </summary>
protected ActorBase Actor { get { return _actor; } }
internal ActorBase Actor { get { return _actor; } }
/// <summary>
/// TBD
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public TerminatingChildrenContainer(IImmutableDictionary<string, IChildStats> ch
_reason = reason;
}

public ImmutableHashSet<IActorRef> ToDie => _toDie;

/// <summary>
/// TBD
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/core/Akka/Actor/ExtendedActorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public abstract class ExtendedActorSystem : ActorSystem
/// </summary>
public abstract void Abort();

public abstract string PrintTree();

//TODO: Missing threadFactory, dynamicAccess, printTree
// /**
// * A ThreadFactory that can be used if the transport needs to create any Threads
Expand Down
74 changes: 74 additions & 0 deletions src/core/Akka/Actor/Internal/ActorSystemImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -16,6 +17,7 @@
using Akka.Dispatch.SysMsg;
using Akka.Event;
using System.Reflection;
using System.Text;
using Akka.Actor.Setup;
using Akka.Serialization;
using Akka.Util;
Expand Down Expand Up @@ -569,6 +571,78 @@ public override string ToString()
{
return LookupRoot.Path.Root.Address.ToString();
}

public override string PrintTree()
{
string PrintNode(IActorRef node, string indent)
{
var sb = new StringBuilder();
if (node is ActorRefWithCell wc)
{
const string space = " ";
var cell = wc.Underlying;
sb.Append(string.IsNullOrEmpty(indent) ? "-> " : indent.Remove(indent.Length-1) + "L-> ")
.Append($"{node.Path.Name} {Logging.SimpleName(node)} ");

if (cell is ActorCell real)
{
var realActor = real.Actor;
sb.Append(realActor is null ? "null" : realActor.GetType().ToString())
.Append($" status={real.Mailbox.CurrentStatus()}");
}
else
{
sb.Append(Logging.SimpleName(cell));
}
sb.Append(space);

switch (cell.ChildrenContainer)
{
case TerminatingChildrenContainer t:
var toDie = t.ToDie.ToList();
toDie.Sort();
var reason = t.Reason;
sb.Append($"Terminating({reason})")
.Append($"\n{indent} | toDie: ")
.Append(string.Join($"\n{indent} | ", toDie));
break;
case TerminatedChildrenContainer x:
sb.Append(x);
break;
case EmptyChildrenContainer x:
sb.Append(x);
break;
case NormalChildrenContainer n:
sb.Append($"{n.Children.Count} children");
break;
case var x:
sb.Append(Logging.SimpleName(x));
break;
}

if (cell.ChildrenContainer.Children.Count > 0)
{
sb.Append("\n");

var children = cell.ChildrenContainer.Children.ToList();
children.Sort();
var childStrings = children.Select((t, i) => i == 0
? PrintNode(t, $"{indent} |")
: PrintNode(t, $"{indent} "));

sb.Append(string.Join("\n", childStrings));
}
}
else
{
sb.Append($"{indent}{node.Path.Name} {Logging.SimpleName(node)}");
}

return sb.ToString();
}

return PrintNode(LookupRoot, "");
}
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/core/Akka/Akka.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<PropertyGroup>
<AssemblyTitle>Akka</AssemblyTitle>
<Description>Akka.NET is a port of the popular Java/Scala framework Akka to .NET</Description>
<TargetFrameworks>$(NetStandardLibVersion)</TargetFrameworks>
<TargetFramework>$(NetStandardLibVersion)</TargetFramework>
<PackageTags>$(AkkaPackageTags)</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<LangVersion>7.2</LangVersion>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down