Tracing the "sender hierarchy" in Scala actors

205 views Asked by At

I'm maintaining a couple of actor-based Scala applications at the moment, and one question I find myself asking all the time is Who sends that message?

For example, I find the piece of code that prints the scary message I found in the logs:

case ReportFailedUpdates(stuff) =>
  log("The horror! The horror! " + stuff)
  dieHorribly()

and I want to find out what might be the cause. If I weren't using actors, I could hit Ctrl+Alt+H (at least in Eclipse) and find out who 'called' this 'method' (and who called that, and who called that). With actors, I find myself searching for ! ReportFailedUpdates( to find which actors send this message, then searching for the senders of the message that actor was reacting to, etc (and usually drawing the result on paper). This has two disadvantages:

  • It's slower, since Eclipse is doing a text search over the (potentially many) project(s) and I'm having to note stuff down
  • It doesn't necessarily find all occurrences, since maybe this was sent with !?, or maybe someone put two spaces between the ! and the ReportFailedUpdates, or, or, or....

What I'd love is some tooling support that lets me find out where a message could have come from - roughly the equivalent of a call hierarchy for non-actor-based code.

Are there any tools that do it? Is this a feature of the ScalaIDE for Eclipse that I just haven't discovered? If I use IntelliJ will my life be better?

Update

My example may have been misleading. This isn't just about figuring out what's gone wrong when it all falls over - I also find myself doing this a lot when I pick up a new system and need to figure out how it works. Seems like there isn't yet a tool to do it. Guess I'll have to have a think myself about how you could start to statically extract (and maybe visualize) the message flow graph...

1

There are 1 answers

3
Derek Wyatt On BEST ANSWER

Well, that is quite the hefty desire, and I'd be extremely impressed if someone were to write it, but I haven't seen anything like that as yet.

Tracing it will be very difficult since there's no "stack" to trace. I'm curious why you don't do this, though:

case ReportFailedUpdates(stuff) =>
    log("The horror! The horror! %s (sent by %s)".format(stuff, sender))
    dieHorribly()

That would at least give you the current link in the chain.

As well - I'm a Vim guy so excuse my ignorance - does your IDE not have a better search mechanism, such as Regexes?