From 25ce71f79a0ce671a7a756bf08f29bad18f20252 Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Mon, 7 Mar 2011 21:54:00 +0100 Subject: [PATCH] Fixing #655: Stopping all actors connected to remote server on shutdown --- .../remoteinterface/RemoteInterface.scala | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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 } }