如何计算特定时间在 akka 系统中活跃的特定类型的演员? [英] How to count actors of a certain type active at a certain time in an akka system?

查看:24
本文介绍了如何计算特定时间在 akka 系统中活跃的特定类型的演员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Akka 2 是否提供了一种方法来确定系统中特定时间活跃的特定类型参与者的数量?

Does Akka 2 provide a way to determine the number of actors of a certain type active at a certain time in the system?

我一直在寻找类似的东西

I've was looking for something like

int actorCount = getContext().count(MyActor.class)

Props props = Props.create(MyActor.class, "actorName")
...
int actorCount = getContext().count(props)

getContext().actorSelection("/path/to/actor").count()

我刚刚开始使用 Java 中的 akka 框架,所以请耐心等待.

I've just started playing with the akka framework in Java, so please bear with me.

推荐答案

[将把这个也作为有效答案]

[Going to put this also as a valid answer]

如果需要计数的 actor 不是父级和/或无法检索目标 actor 的 ActorRef,那么以下可能是替代方案.

If the actor who needs the count is not the parent and/or cannot retrieve the ActorRefs of the target actors, then the following might be an alternative.

计算某种类型的演员的数量可以通过发送人头计数"消息来完成,持有一个ActorRef数组,传递每个演员.然后每个目标参与者可以将它的 ActorRef 添加到该列表中并转发消息.但这取决于系统的性质,并且只有当您毫无疑问地知道在人数统计"期间没有任何演员出现时才有效.

Counting the number of actors of a certain type can be done by sending a "head count" message, holding an ActorRef array, passing each actor. Then each target actor can add it's ActorRef to that list and forward the message. But this depends on the nature of the system and works only if you know beyond any doubt that you don't have any actors spawning up during the "head count".

这篇关于如何计算特定时间在 akka 系统中活跃的特定类型的演员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆