2014-07-26 8 views
5

저는 여러 명의 어린이가있는 Akka 부모 배우가 있습니다. 부모 액터가 다시 시작될 때, 아이를 멈추고 다시 만들거나 다시 시작하지 않고 단순히 자식을 중지해야합니다. (필요할 경우 나중에 수동으로 어린이를 만들 수 있습니다.)이 방법이 있습니까? 어쩌면 부모의 preRestart 메소드를 어떤 방법으로 재정의하면 될까요?부모의 재시작시 아동 배우자를 단순히 멈추는 방법은 무엇입니까?

+0

자녀를 어떻게 만듭니 까? 부모 초기화 중 또는 수신 중 무조건적으로 어떻게해야합니까? –

+0

@AlekseyIzmailov 수신시. – Lasf

+0

부모 초기화 중이 아닌 수신시 작성된 자식은 중지되지만 다시 작성되지 않은 것처럼 보입니다. 그러나, 나는 이것을 확신하지 못했다. 누구나 이것이 실제 행동인지 확인할 수 있습니까? – Lasf

답변

3

기본적으로 Actor은 다시 시작할 때 아이들을 처분합니다. 당신이 부모 중지하고 아이를 주시 해제됩니다 볼 수 있듯이

/** 
    * User overridable callback: '''By default it disposes of all children and then calls `postStop()`.''' 
    * @param reason the Throwable that caused the restart to happen 
    * @param message optionally the current message the actor processed when failing, if applicable 
    * <p/> 
    * Is called on a crashed Actor right BEFORE it is restarted to allow clean 
    * up of resources before Actor is terminated. 
    */ 
    @throws(classOf[Exception]) // when changing this you MUST also change UntypedActorDocTest 
    //#lifecycle-hooks 
    def preRestart(reason: Throwable, message: Option[Any]): Unit = { 
    context.children foreach { child ⇒ 
     context.unwatch(child) 
     context.stop(child) 
    } 
    postStop() 
    } 

다음은 Actor.preRestart 코드입니다.

override def preRestart(reason: Throwable, message: Option[Any]): Unit =() 

그래서 당신의 목적을 위해 당신이 preRestart를 오버라이드 (override) 할 필요가 없습니다 당신은 원하는 동작을 얻을 것이다 : 당신은 배우가 살아 아이들의 유지하기 위해 이런 식으로 재정의 할 수 있습니다. 시작시 자식 시작과 같은 사용자 정의 동작을 원하지만 재시작 이벤트에서는 그렇지 않은 경우 다른 콜백을 볼 수 있습니다.