Skip to content

Commit

Permalink
cleaned up internal ActorCell and TestKit methods (#5091)
Browse files Browse the repository at this point in the history
Found some methods that could be made static on `ActorCell`, which should help with total actor memory footprint.
  • Loading branch information
Aaronontheweb committed Jun 14, 2021
1 parent dfd7925 commit c485d9e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/core/Akka.TestKit/CallingThreadDispatcher.cs
Expand Up @@ -12,7 +12,7 @@
namespace Akka.TestKit
{
/// <summary>
/// TBD
/// INTERNAL API
/// </summary>
public class CallingThreadDispatcherConfigurator : MessageDispatcherConfigurator
{
Expand All @@ -36,7 +36,9 @@ public override MessageDispatcher Dispatcher()
}

/// <summary>
/// TBD
/// INTERNAL API
///
/// Used to run an actor on the foreground thread.
/// </summary>
public class CallingThreadDispatcher : MessageDispatcher
{
Expand Down
11 changes: 4 additions & 7 deletions src/core/Akka.TestKit/Internal/InternalTestActorRef.cs
Expand Up @@ -172,21 +172,18 @@ public static InternalTestActorRef Create(ActorSystem system, Props props, IActo

var dispatcher = system.Dispatchers.Lookup(props.Deploy.Dispatcher);

var supervisorLocal = supervisor as LocalActorRef;
if (supervisorLocal != null)
if (supervisor is LocalActorRef supervisorLocal)
{
supervisorLocal.Cell.ReserveChild(name);
}
else
{
var supervisorRep = supervisor as RepointableActorRef;
if (supervisorRep != null)
if (supervisor is RepointableActorRef supervisorRep)
{
var repUnderlying = supervisorRep.Underlying;
if (repUnderlying is UnstartedCell)
throw new IllegalStateException("Cannot attach a TestActor to an unstarted top-level actor, ensure that it is started by sending a message and observing the reply");
var cellUnderlying = repUnderlying as ActorCell;
if (cellUnderlying != null)
if (repUnderlying is ActorCell cellUnderlying)
{
cellUnderlying.ReserveChild(name);
}
Expand All @@ -197,7 +194,7 @@ public static InternalTestActorRef Create(ActorSystem system, Props props, IActo
}
}

MailboxType mailbox = system.Mailboxes.GetMailboxType(props, dispatcher.Configurator.Config);
var mailbox = system.Mailboxes.GetMailboxType(props, dispatcher.Configurator.Config);
var testActorRef = new InternalTestActorRef((ActorSystemImpl)system, props, dispatcher, mailbox, (IInternalActorRef)supervisor, supervisor.Path / name);

// we need to start ourselves since the creation of an actor has been split into initialization and starting
Expand Down
3 changes: 1 addition & 2 deletions src/core/Akka.TestKit/TestKitBase.cs
Expand Up @@ -170,8 +170,7 @@ protected void InitializeTest(ActorSystem system, ActorSystemSetup config, strin
// Calling sync version here, since .Wait() causes deadlock
AwaitCondition(() =>
{
var repRef = testActor as IRepointableRef;
return repRef == null || repRef.IsStarted;
return !(testActor is IRepointableRef repRef) || repRef.IsStarted;
}, TimeSpan.FromSeconds(5), TimeSpan.FromMilliseconds(10));

if (!(this is INoImplicitSender))
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Actor/ActorCell.cs
Expand Up @@ -315,7 +315,7 @@ void IUntypedActorContext.BecomeStacked(UntypedReceive receive)
BecomeStacked(m => { receive(m); return true; });
}

private long NewUid()
private static long NewUid()
{
// Note that this uid is also used as hashCode in ActorRef, so be careful
// to not break hashing if you change the way uid is generated
Expand Down
6 changes: 3 additions & 3 deletions src/core/Akka/Dispatch/Dispatchers.cs
Expand Up @@ -507,13 +507,13 @@ private Config Config(string id, Config appConfig)
var simpleName = id.Substring(id.LastIndexOf('.') + 1);
return IdConfig(id)
.WithFallback(appConfig)
.WithFallback(ConfigurationFactory.ParseString(string.Format("name: {0}", simpleName)))
.WithFallback(ConfigurationFactory.ParseString($"name: {simpleName}"))
.WithFallback(DefaultDispatcherConfig);
}

private Config IdConfig(string id)
private static Config IdConfig(string id)
{
return ConfigurationFactory.ParseString(string.Format("id: {0}", id));
return ConfigurationFactory.ParseString($"id: {id}");
}


Expand Down

0 comments on commit c485d9e

Please sign in to comment.