如何使用具有不同状态的同一事件处理程序的多个实例?
我有一个 OTP 应用程序,其中包含定期发生的事件。有几位演员想做一些事情来响应这一事件。每个参与者所做的事情都是其自身状态的函数,但除此之外它们是相同的。
我的问题是如何将此设置合并到监督树中。我有一个 gen_event 管理器,每个参与者都是一个事件处理程序。如果不是因为 gen_event 监督很奇怪的话,这会很有效。一旦我的第一个处理程序被 add_sup_handler
处理,其余的处理程序就会因 already_started
而失败,并且充当事件处理程序监督者的 gen_server 就会死亡。
那么我应该在这里做什么呢?我开始认为我应该编写自己的事件管理器来跟踪我的所有演员及其状态。
I have an OTP application with an event that happens periodically. There are several actors that want to do stuff in response to the event. The stuff each actor does is a function of its own state, but otherwise they're identical.
My problem is with how I go about incorporating this setup into a supervision tree. I have a gen_event manager with each actor being an event handler. This would work well if it weren't for the fact that gen_event supervision is weird. Once my first handler is add_sup_handler
'd the rest fail with already_started
and my gen_server that's acting as a supervisor for the event handlers dies.
So what should I do here? I'm starting to think I should just write my own event manager that can keep track of all my actors and their state.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
gen_event:add_handler/3
:gen_event:add_handler/3
: