Skip to content

Commit

Permalink
Improve traceability of ITimerMsg (#7262)
Browse files Browse the repository at this point in the history
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 <arkatufus@yahoo.com>
  • Loading branch information
Aaronontheweb and Arkatufus authored Jun 24, 2024
1 parent 8fd8c62 commit 0fd7ca0
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/core/Akka/Actor/Scheduler/TimerScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0fd7ca0

Please sign in to comment.