diff --git a/akka-core/src/main/scala/remote/RemoteClient.scala b/akka-core/src/main/scala/remote/RemoteClient.scala index 2c810068a2..dcf0870010 100644 --- a/akka-core/src/main/scala/remote/RemoteClient.scala +++ b/akka-core/src/main/scala/remote/RemoteClient.scala @@ -229,6 +229,8 @@ class RemoteClient private[akka] (val hostname: String, val port: Int, val loade override def foreachListener(f: (ActorRef) => Unit): Unit = super.foreachListener(f) + protected override def manageLifeCycleOfListeners = false + def send[T](request: RemoteRequestProtocol, senderFuture: Option[CompletableFuture[T]]): Option[CompletableFuture[T]] = if (isRunning) { if (request.getIsOneWay) { connection.getChannel.write(request) diff --git a/akka-core/src/main/scala/remote/RemoteServer.scala b/akka-core/src/main/scala/remote/RemoteServer.scala index 1bc443eab9..d816aba580 100644 --- a/akka-core/src/main/scala/remote/RemoteServer.scala +++ b/akka-core/src/main/scala/remote/RemoteServer.scala @@ -330,6 +330,8 @@ class RemoteServer extends Logging with ListenerManagement { } } + protected override def manageLifeCycleOfListeners = false + protected[akka] override def foreachListener(f: (ActorRef) => Unit): Unit = super.foreachListener(f) } diff --git a/akka-core/src/main/scala/util/ListenerManagement.scala b/akka-core/src/main/scala/util/ListenerManagement.scala index cfcb5ac2b6..0e17058380 100644 --- a/akka-core/src/main/scala/util/ListenerManagement.scala +++ b/akka-core/src/main/scala/util/ListenerManagement.scala @@ -18,21 +18,26 @@ trait ListenerManagement extends Logging { private val listeners = new ConcurrentSkipListSet[ActorRef] /** - * Adds the listener this this registry's listener list. - * The listener is started by this method. + * Specifies whether listeners should be started when added and stopped when removed or not */ - def addListener(listener: ActorRef) = { - listener.start + protected def manageLifeCycleOfListeners: Boolean = true + + /** + * Adds the listener this this registry's listener list. + * The listener is started by this method if manageLifeCycleOfListeners yields true. + */ + def addListener(listener: ActorRef) { + if (manageLifeCycleOfListeners) listener.start listeners add listener } /** * Removes the listener this this registry's listener list. - * The listener is stopped by this method. + * The listener is stopped by this method if manageLifeCycleOfListeners yields true. */ - def removeListener(listener: ActorRef) = { + def removeListener(listener: ActorRef) { listeners remove listener - listener.stop + if (manageLifeCycleOfListeners) listener.stop } /**