追踪“发送者层次结构”在 Scala 演员中

发布于 2024-12-27 18:29:32 字数 966 浏览 3 评论 0原文

我目前正在维护几个基于 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 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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琉璃繁缕 2025-01-03 18:29:32

嗯,这是一个相当强烈的愿望,如果有人写它,我会印象非常深刻,但我还没有看到这样的东西。

跟踪它会非常困难,因为没有“堆栈”可供跟踪。不过,我很好奇你为什么不这样做:

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

这至少会给你链中当前的链接。

另外 - 我是 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:

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文