Page History
...
이것은 부모가 자식을 책임지는 AKKA의 기본 예외 처리모델과도 부합합니다.부합하며, OOP방식의 소멸순서와도 유사합니다.
다만 부모에게 발생한 예외를 자식에게 전가시키지 않습니다. ( 예외처리모델에 더 상세하게 설명)
Code Block | ||||
---|---|---|---|---|
| ||||
class StartStopActor1 extends Actor { override def preStart(): Unit = { println("first started") context.actorOf(Props[StartStopActor2], "second") } override def postStop(): Unit = println("first stopped") override def receive: Receive = { case "stop" => context.stop(self) } } class StartStopActor2 extends Actor { override def preStart(): Unit = println("second started") override def postStop(): Unit = println("second stopped") // Actor.emptyBehavior is a useful placeholder when we don't // want to handle any messages in the actor. override def receive: Receive = Actor.emptyBehavior } val first = system.actorOf(Props[StartStopActor1], "first") first ! "stop" //OutPut //first started //second started //second stopped //first stopped |
...