Added more flexibility to ListenerManagement
This commit is contained in:
parent
d82a804454
commit
ea2f7bb3b6
3 changed files with 16 additions and 7 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue