【发布时间】:2017-01-23 04:20:01
【问题描述】:
我有一个问题,我的程序的第二次调用给出了不可预测的行为。
我正在尝试确保正常关闭 akka 远程处理应用程序。
我有两个演员系统,一个本地演员系统和一个远程演员系统。
本地演员系统
- 创建两个参与者,一个在本地系统上,一个在远程系统上
- 关闭自己
我先启动远程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(); }
}
远程处理工作正常,但是对于这个关机问题。
【问题讨论】: