Akka2.1/Scala-在actor中创建的节点不会显示在context.children中?
我有一个抽象类,它是一个actor,它有这样一个方法Akka2.1/Scala-在actor中创建的节点不会显示在context.children中?,scala,akka,Scala,Akka,我有一个抽象类,它是一个actor,它有这样一个方法 def getNewConnection(id: String): ActorRef A class that subclasses it defines the method. override def getNewConnection(id: String): ActorRef = { val actorRef = system.actorOf(Props(new RsvpClusterableClientConnecti
def getNewConnection(id: String): ActorRef
A class that subclasses it defines the method.
override def getNewConnection(id: String): ActorRef = {
val actorRef = system.actorOf(Props(new RsvpClusterableClientConnection(service, id)))
actorRef ! Subscribe(clientConnectionId)
actorRef
}
然后它存储actorRef
问题是,当我去的时候,它是空的。
类似地,如果子参与者转到context.parent!“嘿!”家长不会明白的。
如果我查看路径,context.partent显示/users/,而真正的父参与者实际上类似于/users/$2b
我找不到有类似问题的人。
这是在一个类似这样的测试中:
class ZombieTest extends TestKit(ActorSystem("zombietest")) with HelperSpec with ShouldMatchers {
import ExecutionContext.Implicits.global
[...]
val conActor = system.actorOf(Props(new ConnectionActor(testService1)))
}
编辑
AgileSteel是正确的。从系统创建将创建顶级参与者。从上下文创建将创建一个子对象
来自akka文件:
使用默认构造函数创建参与者
返回ActorRef的实例。这是演员的把柄
可用于与参与者交互的实例。ActorRef是
不可变,并且与参与者有一对一的关系
代表。ActorRef还可以序列化和网络感知。这
这意味着您可以序列化它,通过网络发送它,并在网络上使用它
远程主机,它仍将在
原始节点,跨网络
在上面的示例中,参与者是从系统创建的。也是
可以使用actor上下文从其他actor创建actor。
不同之处在于主管层级的安排方式。使用时
当前参与者将作为所创建子对象的主管的上下文
演员。当使用该系统时,它将成为顶级参与者,即
由系统监督(内部监护人)
创建子项时,您应该/必须在
context
上调用actorOf
,而不是system
。在创建子项时,您应该/必须在context
上调用actorOf
而不是system
。我将should替换为must;-)谢谢-我在文档中遗漏了这一点。我将用文档中的引用编辑我的帖子。我将用MUST替换SHOULD;-)谢谢-我在文档中遗漏了这一点。我将用文档中的引用编辑我的帖子。
object Main extends App {
val system = ActorSystem("MySystem") val myActor =
system.actorOf(Props[MyActor], name = "myactor") The call to actorOf
class FirstActor extends Actor { val myActor =
context.actorOf(Props[MyActor], name = "myactor")