From 0fd7ca02050846fed5c139bfe222f0cea75f5dc9 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Mon, 24 Jun 2024 10:55:08 -0500 Subject: [PATCH] Improve traceability of `ITimerMsg` (#7262) This is mostly a Phobos-oriented improvement, aimed at making it easier to keep track of scheduled metrics in systems that use `IWithTimer` heavily. Co-authored-by: Gregorius Soedharmo --- .../Akka/Actor/Scheduler/TimerScheduler.cs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/core/Akka/Actor/Scheduler/TimerScheduler.cs b/src/core/Akka/Actor/Scheduler/TimerScheduler.cs index a619c0645c0..7e9ee80a10a 100644 --- a/src/core/Akka/Actor/Scheduler/TimerScheduler.cs +++ b/src/core/Akka/Actor/Scheduler/TimerScheduler.cs @@ -41,36 +41,39 @@ public Timer(object key, object msg, bool repeat, int generation, ICancelable ta } } - public interface ITimerMsg + public interface ITimerMsg : IWrappedMessage, INoSerializationVerificationNeeded { object Key { get; } int Generation { get; } TimerScheduler Owner { get; } } - private class TimerMsg : ITimerMsg, INoSerializationVerificationNeeded + private class TimerMsg : ITimerMsg { public object Key { get; } public int Generation { get; } public TimerScheduler Owner { get; } - public TimerMsg(object key, int generation, TimerScheduler owner) + public TimerMsg(object key, int generation, TimerScheduler owner, object message) { - this.Key = key; - this.Generation = generation; - this.Owner = owner; + Key = key; + Generation = generation; + Owner = owner; + Message = message; } + + public object Message { get; } public override string ToString() { - return $"TimerMsg(key={Key}, generation={Generation}, owner={Owner})"; + return $"TimerMsg(key={Key}, generation={Generation}, owner={Owner}, message={Message})"; } } private class TimerMsgNotInfluenceReceiveTimeout : TimerMsg, INotInfluenceReceiveTimeout { - public TimerMsgNotInfluenceReceiveTimeout(object key, int generation, TimerScheduler owner) - : base(key, generation, owner) + public TimerMsgNotInfluenceReceiveTimeout(object key, int generation, TimerScheduler owner, object message) + : base(key, generation, owner, message) { } } @@ -196,9 +199,9 @@ private void StartTimer(object key, object msg, TimeSpan timeout, TimeSpan initi ITimerMsg timerMsg; if (msg is INotInfluenceReceiveTimeout) - timerMsg = new TimerMsgNotInfluenceReceiveTimeout(key, nextGen, this); + timerMsg = new TimerMsgNotInfluenceReceiveTimeout(key, nextGen, this, msg); else - timerMsg = new TimerMsg(key, nextGen, this); + timerMsg = new TimerMsg(key, nextGen, this, msg); ICancelable task; if (repeat)