remove ActorRef.stop()

- replace ActorRef.stop() by ActorRefFactory.stop(child) everywhere
- ActorCell “optimizes” this to remove the child from its childrenRefs
  in order to allow immediate recycling of the name
- the lost soul must have a place, for which the Locker has been
  created, where Davy Jones will happily rebind the soul to his ship
  (i.e. set “parent” to the locker to avoid mem leak) and periodically
  revisit it (.stop(), in case of that being lost in comm failure,
  similar .watch() to re-check liveness)
This commit is contained in:
Roland 2011-12-14 00:06:36 +01:00
parent 7da61b6cc1
commit cb85778b12
67 changed files with 328 additions and 238 deletions

View file

@ -66,49 +66,3 @@ trait ConnectionManager {
*/
def remove(deadRef: ActorRef)
}
/**
* Manages local connections for a router, e.g. local actors.
*/
class LocalConnectionManager(initialConnections: Iterable[ActorRef]) extends ConnectionManager {
def this(iterable: java.lang.Iterable[ActorRef]) {
this(JavaConverters.iterableAsScalaIterableConverter(iterable).asScala)
}
case class State(version: Long, connections: Iterable[ActorRef]) extends VersionedIterable[ActorRef] {
def iterable = connections
}
private val state: AtomicReference[State] = new AtomicReference[State](newState())
private def newState() = State(Long.MinValue, initialConnections)
def version: Long = state.get.version
def size: Int = state.get.connections.size
def isEmpty: Boolean = state.get.connections.isEmpty
def connections = state.get
def shutdown() {
state.get.connections foreach (_.stop())
}
@tailrec
final def remove(ref: ActorRef) = {
val oldState = state.get
//remote the ref from the connections.
var newList = oldState.connections.filter(currentActorRef currentActorRef ne ref)
if (newList.size != oldState.connections.size) {
//one or more occurrences of the actorRef were removed, so we need to update the state.
val newState = State(oldState.version + 1, newList)
//if we are not able to update the state, we just try again.
if (!state.compareAndSet(oldState, newState)) remove(ref)
}
}
}