Skip to content

Commit

Permalink
Merge pull request #1829 from JeffCyr/issue-1828
Browse files Browse the repository at this point in the history
Issue #1828 Implemented NobodySurrogate
  • Loading branch information
Aaronontheweb committed Mar 25, 2016
2 parents 3a1a3d9 + 23da580 commit 4619782
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/core/Akka.API.Tests/CoreAPISpec.ApproveCore.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ namespace Akka.Actor
public void Tell(object message, Akka.Actor.IActorRef sender) { }
protected abstract void TellInternal(object message, Akka.Actor.IActorRef sender);
public override string ToString() { }
public Akka.Util.ISurrogate ToSurrogate(Akka.Actor.ActorSystem system) { }
public virtual Akka.Util.ISurrogate ToSurrogate(Akka.Actor.ActorSystem system) { }
public class Surrogate : Akka.Util.ISurrogate
{
public Surrogate(string path) { }
Expand Down Expand Up @@ -1212,6 +1212,12 @@ namespace Akka.Actor
public static Akka.Actor.Nobody Instance;
public override Akka.Actor.ActorPath Path { get; }
public override Akka.Actor.IActorRefProvider Provider { get; }
public override Akka.Util.ISurrogate ToSurrogate(Akka.Actor.ActorSystem system) { }
public class NobodySurrogate : Akka.Util.ISurrogate
{
public NobodySurrogate() { }
public Akka.Util.ISurrogated FromSurrogate(Akka.Actor.ActorSystem system) { }
}
}
public class OneForOneStrategy : Akka.Actor.SupervisorStrategy
{
Expand Down
10 changes: 9 additions & 1 deletion src/core/Akka.Remote.Tests/RemotingSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ public void Drop_received_messages_over_payload_size()
});
}

[Fact]
public void Nobody_should_be_converted_back_to_its_singleton()
{
here.Tell(ActorRefs.Nobody, TestActor);
ExpectMsg(ActorRefs.Nobody, TimeSpan.FromSeconds(1.5));
}

#endregion

#region Internal Methods
Expand Down Expand Up @@ -456,7 +463,8 @@ protected override void OnReceive(object message)
{
actorTuple.Item2.Tell(Tuple.Create("pong", Sender.Path.ToSerializationFormat()));
}
});
})
.Default(msg => Sender.Tell(msg));
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/core/Akka/Actor/ActorRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public int CompareTo(IActorRef other)
return Path.Uid == other.Path.Uid ? 0 : 1;
}

public ISurrogate ToSurrogate(ActorSystem system)
public virtual ISurrogate ToSurrogate(ActorSystem system)
{
return new Surrogate(Serialization.Serialization.SerializedActorPath(this));
}
Expand Down Expand Up @@ -338,7 +338,15 @@ public override bool IsLocal
/// <summary> This is an internal look-up failure token, not useful for anything else.</summary>
public sealed class Nobody : MinimalActorRef
{
public class NobodySurrogate : ISurrogate
{
public ISurrogated FromSurrogate(ActorSystem system)
{
return Nobody.Instance;
}
}
public static Nobody Instance = new Nobody();
private static readonly NobodySurrogate SurrogateInstance = new NobodySurrogate();
private readonly ActorPath _path = new RootActorPath(Address.AllSystems, "/Nobody");

private Nobody() { }
Expand All @@ -350,6 +358,10 @@ public override IActorRefProvider Provider
get { throw new NotSupportedException("Nobody does not provide"); }
}

public override ISurrogate ToSurrogate(ActorSystem system)
{
return SurrogateInstance;
}
}

public abstract class ActorRefWithCell : InternalActorRefBase
Expand Down

0 comments on commit 4619782

Please sign in to comment.