Added more flexibility to ListenerManagement

This commit is contained in:
Viktor Klang 2010-08-19 12:46:17 +02:00
parent d82a804454
commit ea2f7bb3b6
3 changed files with 16 additions and 7 deletions

View file

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

View file

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

View file

@ -18,21 +18,26 @@ trait ListenerManagement extends Logging {
private val listeners = new ConcurrentSkipListSet[ActorRef]
/**
* Adds the <code>listener</code> this this registry's listener list.
* The <code>listener</code> 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 <code>listener</code> this this registry's listener list.
* The <code>listener</code> is started by this method if manageLifeCycleOfListeners yields true.
*/
def addListener(listener: ActorRef) {
if (manageLifeCycleOfListeners) listener.start
listeners add listener
}
/**
* Removes the <code>listener</code> this this registry's listener list.
* The <code>listener</code> is stopped by this method.
* The <code>listener</code> 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
}
/**