Skip to content

Commit c485d9e

Browse files
cleaned up internal ActorCell and TestKit methods (#5091)
Found some methods that could be made static on `ActorCell`, which should help with total actor memory footprint.
1 parent dfd7925 commit c485d9e

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

src/core/Akka.TestKit/CallingThreadDispatcher.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Akka.TestKit
1313
{
1414
/// <summary>
15-
/// TBD
15+
/// INTERNAL API
1616
/// </summary>
1717
public class CallingThreadDispatcherConfigurator : MessageDispatcherConfigurator
1818
{
@@ -36,7 +36,9 @@ public override MessageDispatcher Dispatcher()
3636
}
3737

3838
/// <summary>
39-
/// TBD
39+
/// INTERNAL API
40+
///
41+
/// Used to run an actor on the foreground thread.
4042
/// </summary>
4143
public class CallingThreadDispatcher : MessageDispatcher
4244
{

src/core/Akka.TestKit/Internal/InternalTestActorRef.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,18 @@ public static InternalTestActorRef Create(ActorSystem system, Props props, IActo
172172

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

175-
var supervisorLocal = supervisor as LocalActorRef;
176-
if (supervisorLocal != null)
175+
if (supervisor is LocalActorRef supervisorLocal)
177176
{
178177
supervisorLocal.Cell.ReserveChild(name);
179178
}
180179
else
181180
{
182-
var supervisorRep = supervisor as RepointableActorRef;
183-
if (supervisorRep != null)
181+
if (supervisor is RepointableActorRef supervisorRep)
184182
{
185183
var repUnderlying = supervisorRep.Underlying;
186184
if (repUnderlying is UnstartedCell)
187185
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");
188-
var cellUnderlying = repUnderlying as ActorCell;
189-
if (cellUnderlying != null)
186+
if (repUnderlying is ActorCell cellUnderlying)
190187
{
191188
cellUnderlying.ReserveChild(name);
192189
}
@@ -197,7 +194,7 @@ public static InternalTestActorRef Create(ActorSystem system, Props props, IActo
197194
}
198195
}
199196

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

203200
// we need to start ourselves since the creation of an actor has been split into initialization and starting

src/core/Akka.TestKit/TestKitBase.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ protected void InitializeTest(ActorSystem system, ActorSystemSetup config, strin
170170
// Calling sync version here, since .Wait() causes deadlock
171171
AwaitCondition(() =>
172172
{
173-
var repRef = testActor as IRepointableRef;
174-
return repRef == null || repRef.IsStarted;
173+
return !(testActor is IRepointableRef repRef) || repRef.IsStarted;
175174
}, TimeSpan.FromSeconds(5), TimeSpan.FromMilliseconds(10));
176175

177176
if (!(this is INoImplicitSender))

src/core/Akka/Actor/ActorCell.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ void IUntypedActorContext.BecomeStacked(UntypedReceive receive)
315315
BecomeStacked(m => { receive(m); return true; });
316316
}
317317

318-
private long NewUid()
318+
private static long NewUid()
319319
{
320320
// Note that this uid is also used as hashCode in ActorRef, so be careful
321321
// to not break hashing if you change the way uid is generated

src/core/Akka/Dispatch/Dispatchers.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,13 +507,13 @@ private Config Config(string id, Config appConfig)
507507
var simpleName = id.Substring(id.LastIndexOf('.') + 1);
508508
return IdConfig(id)
509509
.WithFallback(appConfig)
510-
.WithFallback(ConfigurationFactory.ParseString(string.Format("name: {0}", simpleName)))
510+
.WithFallback(ConfigurationFactory.ParseString($"name: {simpleName}"))
511511
.WithFallback(DefaultDispatcherConfig);
512512
}
513513

514-
private Config IdConfig(string id)
514+
private static Config IdConfig(string id)
515515
{
516-
return ConfigurationFactory.ParseString(string.Format("id: {0}", id));
516+
return ConfigurationFactory.ParseString($"id: {id}");
517517
}
518518

519519

0 commit comments

Comments
 (0)