From fd757fb680485c997b55a4ceda80e961666af77a Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Tue, 25 Sep 2012 15:08:08 +0200 Subject: [PATCH] Terminate remote deployed actors when parent node goes down, see #2551 * RemoteSystemDaemon listens to AddressTerminated and stops matching children --- .../src/main/scala/akka/remote/RemoteDaemon.scala | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/akka-remote/src/main/scala/akka/remote/RemoteDaemon.scala b/akka-remote/src/main/scala/akka/remote/RemoteDaemon.scala index ccdeee439b..ac07e2211c 100644 --- a/akka-remote/src/main/scala/akka/remote/RemoteDaemon.scala +++ b/akka-remote/src/main/scala/akka/remote/RemoteDaemon.scala @@ -5,7 +5,7 @@ package akka.remote import scala.annotation.tailrec -import akka.actor.{ VirtualPathContainer, Terminated, Deploy, Props, Nobody, LocalActorRef, InternalActorRef, Address, ActorSystemImpl, ActorRef, ActorPathExtractor, ActorPath, Actor } +import akka.actor.{ VirtualPathContainer, Terminated, Deploy, Props, Nobody, LocalActorRef, InternalActorRef, Address, ActorSystemImpl, ActorRef, ActorPathExtractor, ActorPath, Actor, AddressTerminated } import akka.event.LoggingAdapter import akka.dispatch.Watch import akka.actor.ActorRefWithCell @@ -26,9 +26,11 @@ private[akka] class RemoteSystemDaemon(system: ActorSystemImpl, _path: ActorPath import akka.actor.Guardian._ + @volatile private var terminating = false + system.provider.systemGuardian.tell(RegisterTerminationHook, this) - @volatile private var terminating = false + system.eventStream.subscribe(this, classOf[AddressTerminated]) /** * Find the longest matching path which we know about and return that ref @@ -89,6 +91,9 @@ private[akka] class RemoteSystemDaemon(system: ActorSystemImpl, _path: ActorPath terminationHookDoneWhenNoChildren() allChildren foreach system.stop + case AddressTerminated(address) ⇒ + allChildren filter { _.asInstanceOf[InternalActorRef].getParent.path.address == address } foreach system.stop + case unknown ⇒ log.warning("Unknown message {} received by {}", unknown, this) }