Here is the outline of my code
There are multiple worker actors and I am collecting some latency stats from them into httpActorLatencies
map where latency from each worker actor is tracked separately and then logged on receiving LogQueueLatency
message. At this point, all the queues in httpActorLatencies
are also cleared.
Is there a way to get rid of mutable Map in a reasonable way?
class StatsActor(workerCount: Int) extends Actor {
val httpActorLatencies = scala.collection.mutable.Map[Int, scala.collection.mutable.MutableList[Long]]()
override def preStart(): Unit = {
Range(0, workerCount).foreach(i => httpActorLatencies.put(i, scala.collection.mutable.MutableList()))
}
override def receive = {
case shardLatency: QueuingLatency =>
httpActorLatencies(shardLatency.shardNumber) += shardLatency.latency
case LogQueueLatency =>
outputCollectedStats()
}
private def outputCollectedStats(): Unit = {
output(StatsActor.computePerShardMeanLatencies(httpActorLatencies))
httpActorLatencies.foreach(x => x._2.clear())
}
}