diff --git a/akka-actor/src/main/scala/akka/remoteinterface/RemoteInterface.scala b/akka-actor/src/main/scala/akka/remoteinterface/RemoteInterface.scala index 4e78446396..ed0122dd61 100644 --- a/akka-actor/src/main/scala/akka/remoteinterface/RemoteInterface.scala +++ b/akka-actor/src/main/scala/akka/remoteinterface/RemoteInterface.scala @@ -216,7 +216,33 @@ abstract class RemoteSupport extends ListenerManagement with RemoteServerModule private[akka] val typedActorsFactories = new ConcurrentHashMap[String, () => AnyRef] def clear { - List(actors,actorsByUuid,actorsFactories,typedActors,typedActorsByUuid,typedActorsFactories) foreach (_.clear) + def clearActorMap(map: ConcurrentHashMap[String, ActorRef]) { + val i = map.values.iterator + while (i.hasNext) { + i.next match { + case ref: LocalActorRef => try { ref.stop } catch { case e: Exception => } + case _ => + } + } + map.clear + } + + def clearTypedActorMap(map: ConcurrentHashMap[String, AnyRef]) { + ReflectiveAccess.TypedActorModule.typedActorObjectInstance foreach { + case typedActor => + val i = map.values.iterator + //FIXME Only stop local TypedActor? + while (i.hasNext) { try { typedActor.stop(i.next) } catch { case e: Exception => } } + } + map.clear + } + + clearActorMap(actors) + clearActorMap(actorsByUuid) + clearTypedActorMap(typedActors) + clearTypedActorMap(typedActorsByUuid) + actorsFactories.clear + typedActorsFactories.clear } }