akka.pattern
Interface GracefulStopSupport


public interface GracefulStopSupport


Method Summary
 scala.concurrent.Future<java.lang.Object> gracefulStop(ActorRef target, scala.concurrent.duration.FiniteDuration timeout, java.lang.Object stopMessage)
          Returns a Future that will be completed with success (value true) when existing messages of the target actor has been processed and the actor has been terminated.
 

Method Detail

gracefulStop

scala.concurrent.Future<java.lang.Object> gracefulStop(ActorRef target,
                                                       scala.concurrent.duration.FiniteDuration timeout,
                                                       java.lang.Object stopMessage)
Returns a Future that will be completed with success (value true) when existing messages of the target actor has been processed and the actor has been terminated.

Useful when you need to wait for termination or compose ordered termination of several actors, which should only be done outside of the ActorSystem as blocking inside Actors is discouraged.

IMPORTANT NOTICE: the actor being terminated and its supervisor being informed of the availability of the deceased actor&rsquo;s name are two distinct operations, which do not obey any reliable ordering. Especially the following will NOT work:


 def receive = {
   case msg =>
     Await.result(gracefulStop(someChild, timeout), timeout)
     context.actorOf(Props(...), "someChild") // assuming that that was someChild&rsquo;s name, this will NOT work
 }
 

If the target actor isn't terminated within the timeout the Future is completed with failure AskTimeoutException.

If you want to invoke specialized stopping logic on your target actor instead of PoisonPill, you can pass your stop command as a parameter:


   gracefulStop(someChild, timeout, MyStopGracefullyMessage).onComplete {
      // Do something after someChild being stopped
   }
 

Parameters:
target - (undocumented)
timeout - (undocumented)
stopMessage - (undocumented)
Returns:
(undocumented)