【问题标题】:Termination of remote Akka Actor System远程 Akka Actor 系统的终止
【发布时间】:2017-01-23 04:20:01
【问题描述】:

我有一个问题,我的程序的第二次调用给出了不可预测的行为。

我正在尝试确保正常关闭 akka 远程处理应用程序。

我有两个演员系统,一个本地演员系统和一个远程演员系统。

本地演员系统

  1. 创建两个参与者,一个在本地系统上,一个在远程系统上
  2. 关闭自己

我先启动远程actor系统,然后运行本地actor系统。

当我第一次运行时,一切正常,本地演员系统关闭(远程仍然启动)。但是如果我第二次运行它(不重新启动远程系统),行为就会不同,两个参与者系统开始心跳。 本地没有关闭。

复制行为的最少代码如下

本地演员系统

object ActorAsSink_7  extends App {
    val system = ActorSystem("system")
    val localActor = system.actorOf(MyActor_4.props)
    val remoteActor = system.actorOf(MyActor_4.props, "remote_agent") 
    localActor ! PoisonPill
}

远程演员系统

object RemoteActorSystem  extends App {

  import system.dispatcher
  implicit val system = ActorSystem("remote-actorsystem")

  // actors in this actor system are created remotely

  println("hello.. remote agent is up")

}

这是一个更大的代码库的一部分,这是我能够找到的最小的复制问题。

为什么我的本地演员系统表现不同,并且在第二次调用中没有关闭?

本地演员执行以下操作

object MyActor_4 {
  val props = Props[MyActor_4]
}

class MyActor_4 extends Actor with ActorLogging {
  def receive = { case x: Any  => log.error("unexpected message in reaper: " + x)  }
  override def postStop = { println ("shutting down...") ;  context.system.terminate(); }  
}

远程处理工作正常,但是对于这个关机问题。

【问题讨论】:

    标签: akka actor


    【解决方案1】:

    根据我的理解,下面的代码行不会停止 remoteActor。

        localActor ! PoisonPill
    

    因为 PoisonPill 会停止发送方 Actor 及其所有子 Actor。 这里 remoteActor 不是 localActor 的子 Actor。 你能分享一下本地演员系统的两个演员在第一次运行时停止的日志吗?

    【讨论】:

    • 要关闭ActorSystem,你可以这样做system.shutdown要停止localActor和remoteActor而不停止ActorSystemsystem.actorSelection("/user/*") ! PoisonPill可以查看更多详细信息stackoverflow.com/questions/9356986/…
    猜你喜欢
    • 1970-01-01
    • 2012-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-06
    • 2013-01-25
    • 2015-09-09
    • 1970-01-01
    相关资源
    最近更新 更多