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

Issue #1828 Implemented NobodySurrogate #1829

Merged
merged 1 commit into from
Mar 25, 2016
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
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