Created
December 20, 2015 06:30
-
-
Save maxim-s/bd11eae2388b0ea2e7ed to your computer and use it in GitHub Desktop.
RemoteDaemon GetChild implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override IActorRef GetChild(IEnumerable<string> name) | |
{ | |
string[] parts = name.ToArray(); | |
if (!parts.Any()) | |
return this; | |
var n = parts.First(); | |
if (string.IsNullOrEmpty(n)) | |
return this; | |
var joined = string.Join("/", parts); | |
var child = GetChild(joined); | |
if (child != null) | |
{ | |
return child; | |
} | |
var last = joined.LastIndexOf("/", StringComparison.Ordinal); | |
var i = 1; | |
while (last != -1 || parts.Length <=i) | |
{ | |
var s = joined.Substring(0, last); | |
child = GetChild(s); | |
if (child != null) | |
{ | |
return child.GetChild(parts.Skip(Math.Max(0, parts.Length - i))); | |
} | |
last = s.LastIndexOf("/", StringComparison.Ordinal); | |
i++; | |
} | |
return ActorRefs.Nobody; | |
} | |
private IInternalActorRef GetChild(string name) | |
{ | |
IInternalActorRef child; | |
if (TryGetChild(name, out child)) | |
{ | |
var uid = GetdUid(name); | |
if (uid != ActorCell.UndefinedUid && uid != child.Path.Uid) | |
{ | |
return ActorRefs.Nobody; | |
} | |
} | |
return child; | |
} | |
private int GetdUid(string name) | |
{ | |
var i = name.IndexOf("#"); | |
if (i < 0) | |
{ | |
return ActorCell.UndefinedUid; | |
} | |
return int.Parse(name.Substring(i + 1)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment