문제

In akka the poststop method is called when an actor is stopped.

Also a watch can be configured on the supervisor so that when an actor is terminated a Terminated message is received within the supervisor.

Is there any advantage of using the postStop instead of Terminated? The only difference I can see is that postStop is called(within actor) when an actor is stopped and Terminated is called(within supervisor) when actor is Terminated.

When an actor is stopped is'nt it also terminated ?

도움이 되었습니까?

해결책

First of all, postStop() is called from preRestart() default implementation of the same actor (see here), while Terminated message is sent to the parent only when the actor is really stopped, not when it is just restarted. Hence in default setup postStop() may be called more times than Terminated message is sent.

But the main idea is that post* and pre* hooks are needed to cleanup the actor's own state, and Terminated message (the whole watch system, in fact) is intended to coordinate multiple actors behavior and state. Their purpose is different, and while you can send custom Terminated-like messages from postStop() hook, you really shouldn't.

다른 팁

postStop is a callback inside the actor itself. You would use that to clean up state that is internal to the actor, or fire further messages based on the state.

Watching for Terminated allows an external actor to be notified when another actor has died. It does not rely on the terminated actor itself to do anything.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top