직선적 인 감독 계층 구조를 상상해보십시오. 아이가 죽는다. 아버지는 그 아이를 Restart
로 결정합니다. Restart
ed 일 때 postRestart
과 친구들을 부르지 만, 아버지가 그 아이를 다시 시작하기로 결정했다면 어떻게 될까요? 아동 배우가 그가 재개된다는 것을 알고 있습니까? 그리고 btw. 아버지는 자녀에게 예외를 발생시킨 메시지에 접근 할 수 있습니까?아동 배우는 그가 재개된다는 것을 알고 있습니까?
답변
이력서는 "실제로 아무 일도 일어나지 않았다"는 의미이며,이 정신에서 아이에게도 정보가 제공되지 않습니다. 거의 사용하지 않아야하는 지시어입니다.
부모는 문제의 원인이 된 메시지가 아니라 장애 자체 (예 : Throwable
) 만 수신합니다. 부모와 자녀의 논리를 건강한 것 이상으로 얽히게 할 수 있기 때문입니다.
감독자의 supervisorStrategy에서 이러한 종류의 동작을 올바르게 설정하면 Supervisor에 오류가 발생할 수 있습니다.
import akka.actor.Actor
import akka.actor.Props
import akka.actor.ActorSystem
object SupervisorTest {
def main(args: Array[String]) {
val system = ActorSystem("test")
val master = system.actorOf(Props[Master], "master")
master ! "foo"
Thread.sleep(500)
val worker = system.actorFor("/user/master/foo")
worker ! "bar"
}
}
class Master extends Actor{
import akka.actor.OneForOneStrategy
import akka.actor.SupervisorStrategy._
import scala.concurrent.duration._
override val supervisorStrategy =
OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) {
case _: Exception => Escalate
Escalate
}
override def preRestart(ex:Throwable, msg:Option[Any]) = {
println("In master restart: " + msg)
}
def receive = {
case msg:String =>
context.actorOf(Props[Worker], msg)
}
}
class Worker extends Actor{
override def preRestart(ex:Throwable, msg:Option[Any]) = {
println("In worker restart: " + msg)
}
def receive = {
case _ =>
throw new Exception("error!!")
}
}
당신은 Master
배우 (내 예에서 관리자), 내가 Escalate
에 유형 Exception
의 실패를 선택하고에서 볼 수 있습니다 약간의 예는 그 동작을 표시합니다. 이로 인해 실패가 Master
액터의 preRestart
까지 버블 링됩니다. 이제 msg
매개 변수가 preRestart
으로 작업자 액터로 전달 된 원래의 불쾌 메시지가 될 것으로 예상했지만 그렇지 않았습니다. 내가 보여준 유일한 방법은 하위 액터의 preRestart
도 무시하는 것입니다. 예를 들어, 감독관과 자녀 모두의 인쇄물을 순서대로 볼 수 있습니다.
그러나 아이를 다시 시작하면 어떨까요? 그때는 다시 시작하지 않습니다. 그렇죠? 따라서'preRestart'와 친구들은 호출되지 않습니다. – agilesteel
다시 시작이라는 용어는 메시지 처리를 계속하며 문서의 두 지점에서 참조됩니다.
제 예외 상태에 대한 응답으로 사용된다 를 akka 문서 당 같이 실제로 재시작
As described in Actor Systems supervision describes a dependency relationship between actors: the supervisor delegates tasks to subordinates and therefore must respond to their failures. When a subordinate detects a failure (i.e. throws an exception), it suspends itself and all its subordinates and sends a message to its supervisor, signaling failureDepending on the nature of the work to be supervised and the nature of the failure, the supervisor has a choice of the following four options:
Resume the subordinate, keeping its accumulated internal state
Restart the subordinate, clearing out its accumulated internal state
Terminate the subordinate permanently
Escalate the failure, thereby failing itself
참고 일본어 배우 명. 이력서라는 용어는 여기에서 다시 사용되어 메시지 처리를 계속한다는 의미입니다.
akka 설명서에 따라.
The precise sequence of events during a restart is the following:
- suspend the actor (which means that it will not process normal messages until resumed), and recursively suspend all children
- call the old instance’s preRestart hook (defaults to sending termination requests to all children and calling postStop)
- wait for all children which were requested to terminate (using context.stop()) during preRestart to actually terminate; this—like all actor operations—is non-blocking, the termination notice from the last killed child will effect the progression to the next step
- create new actor instance by invoking the originally provided factory again
- invoke postRestart on the new instance (which by default also calls preStart)
- send restart request to all children which were not killed in step 3; restarted children will follow the same process recursively, from step 2
- resume the actor
- 1. 누구든지 kCCDirectorProjection2D가하는 것을 알고 있습니까?
- 2. 보기가 그가 전방으로 되돌아온 것을 어떻게 알 수 있습니까?
- 3. emacs는 배우는 가치가 있습니까?
- 4. JavaScript는 NaN이지만, 그렇지 않은 것을 알고 있습니까?
- 5. PHP는 연결이 닫힌 것을 알고 있습니까?
- 6. 소스 코드가 테스트 중이라는 것을 알고 있습니까?
- 7. FileSystemObject는 파일이 불완전하다는 것을 알고 있습니까?
- 8. 픽셀이 투명하다는 것을 알고
- 9. Pylons는 여전히 배우는 가치가 있습니까?
- 10. Linq에 아동
- 11. 차이 (아동)
- 12. 아동 프로세스
- 13. 양식을 자동 저장하는 방법을 알고 새로운 것을 알고 싶습니다.
- 14. 배우는 컴파일러
- 15. PDO를 배우는 것이 가치가 있습니까?
- 16. 2014 년 ColdFusion을 배우는 것이 가치가 있습니까?
- 17. 아동 C#에서
- 18. C++ QObject를의 아동 관리
- 19. RavenDB : 아동 수집 교차로
- 20. youtube는 당신이 동일한 비디오를 올린 것을 어떻게 알고 있습니까?
- 21. 누구나 PHP 용 RSPec과 같은 것을 알고 있습니까?
- 22. 자바 스크립트 채팅을 쉽게 설치할 수 있다는 것을 알고 있습니까?
- 23. Visual Studio에서 구조체 내의 변수가 null이되는 것을 알고 있습니까?
- 24. 다른 사람이 tableGrob의 속도가 느린 것을 알고 있습니까?
- 25. PHP substr - HTML 태그를 끝내는 것을 알고 있습니까?
- 26. GDB는 지정된 중단 점에서 중단되어야한다는 것을 어떻게 알고 있습니까?
- 27. 누군가 SWT의 PropertyEditor 또는 PropertyGrid와 같은 것을 알고 있습니까?
- 28. 누군가 jquery 모바일과 jquery가 함께 작동하는 것을 알고 있습니까?
- 29. 누구도 Colrd Menu Effect 또는 비슷한 것을 알고 있습니까?
- 30. PHP 프레임 워크의보기 구현이 편리하다는 것을 알고 있습니까?
동의합니다. 그러나이 점을 이해하는 것이 자녀의 상태를 보존 할 수있는 유일한 방법입니다. – agilesteel
동의합니다 - 때로는 아이의 상태가 재시작시 다시 작성하기가 쉽지 않습니다. 우리는이 사건에서 이력서를 사용하여 전체 수신에 큰 시도/포착을하지 않도록합니다. – sourcedelica
예외 상태에 대한 응답에 대해 이야기하는 경우 이는 사실 일 수 있지만 이력서라는 용어는 akka 설명서에 따라 다시 시작주기의 마지막 단계를 참조 할 수도 있습니다 (자세한 내용은 내 대답 참조). – JasonG