postStop
メソッドを使用して停止したときにクリーンアップジョブを実行したい俳優p: ParentActor
があります。仕事の1つは、子供の俳優c: ChildActor
にメッセージを送信することです。その後、c
、次にp
を停止する必要があります。しかし、一度context.stop(p)
と呼ばれると、すぐに停止しているようで、メッセージを受け取ることができません。c
エラーメッセージの親アクターが停止したときに子供のAkka俳優をすぐに停止しないでください
class ParentActor extends Actor {
...
override def postStop {
logger.info("Shutdown message received. Sending message to child...")
val future = c ? "doThing"
logger.info("Waiting for child to complete task...")
Await.result(future, Duration.Inf)
context.stop(c)
logger.info("Child stopped. Stopping self. Bye!")
context.stop(self)
}
}
結果::以下
は私がやりたいものの一例である[ERROR] [SetSystem-akka.actor.default-dispatcher-5] [akka://SetSystem/user/ParentActor] Recipient[Actor[akka://SetSystem/user/ParentActor/ChildActor#70868360]] had already been terminated. Sender[Actor[akka://SetSystem/user/ParentActor#662624985]] sent the message of type "java.lang.String".
代替は、シャットダウンに言っp
メッセージを送ることであろうと、上記のアクションがその結果として起こることがありますが、組み込みの停止機能を使用するほうが優れています。
PS。これは新しいアプリケーションなので、設計の選択肢は大歓迎です。