All started with question “Scala, Actors, what happens to unread inbox messages?“. I was thinking how to avoid such problems in large system with many actors.
I found myself writing something like this:
react {
//all cases
case any: AnyRef => logMessageWithoutCase(any)
}
Is it good avoidance from memory leaks or is it have some side effects?
UPDATE 1 Thanks to @Alexey Romanov and @Luigi Plinge, if in the system will have some Spam actor?
Something like this:
react{
//all cases
case msg: Any => Spam!msg
}
And finally in Spam will log or save to database. I think, it is more intuitive solution.
You might also investigate using Akka actors, which do not suffer from this problem because they enforce in-sequence message processing. Here, unhandled messages get passed to the
unhandled()callback, which by default logs and throws an exception.Another thing to consider is that Akka actors will replace the current scala.actor package in the medium term. This will be especially beneficial for large systems with many actors, because the current Scala actors are not as light-weight as Akka actors.