Terminate remote deployed actors when parent node goes down, see #2551

* RemoteSystemDaemon listens to AddressTerminated and stops matching children
This commit is contained in:
Patrik Nordwall 2012-09-25 15:08:08 +02:00
parent d6e5b0a46b
commit fd757fb680

View file

@ -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)
}