Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 阿克卡亲子关系的后果_Scala_Akka_Actor - Fatal编程技术网

Scala 阿克卡亲子关系的后果

Scala 阿克卡亲子关系的后果,scala,akka,actor,Scala,Akka,Actor,通过上面的例子,我只能想到没有明确的亲子关系的两个后果 毒丸不会明确杀死ParentWithActorRefs中包含的演员引用 ParentWithActorRefs的context.children将为空 它们还有其他后果吗?非子消息中继是否可能与子消息中继具有不同的消息排序语义?我不能使用actorSelection访问ParentWithExplicitChildren的儿童演员引用吗 您的前两个结果是正确的。你错过了一个,当ParentWithExplicitChildren自身失败时,

通过上面的例子,我只能想到没有明确的亲子关系的两个后果

  • 毒丸不会明确杀死ParentWithActorRefs中包含的演员引用
  • ParentWithActorRefs的context.children将为空

  • 它们还有其他后果吗?非子消息中继是否可能与子消息中继具有不同的消息排序语义?我不能使用actorSelection访问ParentWithExplicitChildren的儿童演员引用吗

    您的前两个结果是正确的。你错过了一个,当
    ParentWithExplicitChildren
    自身失败时,它会停止,然后重新启动它的所有子项,因为它是这些子项的显式主管。对于
    ParentWithActorRefs
    ,此actor中的故障不会停止
    shamChildren
    ,因为它不是他们的主管;根守护者是


    此外,是的,您可以通过参与者选择访问
    ParentWithExplicitChildren
    refs的子级。他们是具有可寻址路径的适当参与者,因此可以从他们的家长/主管参与者之外进行查找和交流。

    正如一个说明,在
    ParentWithExplicitChildren
    中,您不需要
    val children
    ,因为孩子总是可以通过
    上下文访问。children
    。您不需要显式的
    val
    来保存这些引用。此外,也不需要关闭“as”来创建顶级“children”,只需使用“context.system”。
    import akka.actor._
    case object ChildMessage
    
    implicit val as = ActorSystem()
    
    class Child extends Actor {
      def receive = {
        case ChildMessage => println("I'm a child")
      }
    }
    
    class ParentWithExplicitChildren extends Actor {
      val children = Array.fill(5)(context.actorOf(Props[Child]))
      def receive = {
        case ChildMessage => children.foreach(_ ! ChildMessage)
        case _ => println("I'm a parent")
      }
    }
    
    class ParentWithActorRefs extends Actor {
      val shamChildren = Array.fill(5)(as.actorOf(Props[Child]))
      def receive = {
        case ChildMessage => shamChildren.foreach(_ ! ChildMessage)
        case _ => println("I'm a parent")
      }
    }
    
    val parent = as.actorOf(Props[ParentWithExplicitChildren])
    parent ! ChildMessage
    // Will shut down children
    parent ! PoisonPill
    
    
    val shamParent = as.actorOf(Props[ParentWithActorRefs])
    shamParent ! ChildMessage
    // WONT shut down children
    shamParent ! PoisonPill