追踪“发送者层次结构”在 Scala 演员中
我目前正在维护几个基于 Actor 的 Scala 应用程序,我发现自己一直在问的一个问题是谁发送该消息?
例如,我找到了打印的一段代码我在日志中发现的可怕消息:
case ReportFailedUpdates(stuff) =>
log("The horror! The horror! " + stuff)
dieHorribly()
我想找出可能的原因。如果我没有使用 actor,我可以按 Ctrl+Alt+H
(至少在 Eclipse 中)并找出谁“调用”了这个“方法”(以及谁调用了该方法,以及谁调用了 < em>那个)。对于演员,我发现自己在寻找! ReportFailedUpdates(
来查找哪些参与者发送此消息,然后搜索该参与者正在响应的消息的发送者,等等(通常将结果绘制在这有两个缺点:
- 速度较慢,因为 Eclipse 正在对(可能有很多)项目进行文本搜索,并且我必须记下内容
- 它不一定能找到所有出现的情况,因为这可能是发送与
!?
,或者也许有人在!
和ReportFailedUpdates
之间放了两个空格,或者,或者,或者......
我会做什么love 是一些工具支持,可以让我找出消息的来源 - 大致相当于非基于参与者的代码的调用层次结构
吗? ScalaIDE for Eclipse 的一个我还没有的功能发现?如果我使用 IntelliJ,我的生活会更好吗?
更新
我的例子可能具有误导性,这不仅仅是为了找出问题所在 - 我也发现自己在这样做。当我拿起一个新系统并需要弄清楚它是如何工作时,我经常会遇到这样的情况。似乎还没有一个工具可以做到这一点。我想我必须自己思考一下如何开始静态提取(并且可能可视化)消息流图......
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 theReportFailedUpdates
, 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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,这是一个相当强烈的愿望,如果有人写它,我会印象非常深刻,但我还没有看到这样的东西。
跟踪它会非常困难,因为没有“堆栈”可供跟踪。不过,我很好奇你为什么不这样做:
这至少会给你链中当前的链接。
另外 - 我是 Vim 人,所以请原谅我的无知 - 你的 IDE 没有更好的搜索机制,例如正则表达式吗?
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:
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?