EventStream should publish to all matching traits. See #2525

This commit is contained in:
Björn Antonsson 2012-09-25 12:32:56 +02:00
parent 3307b6ebce
commit 426120f50c
3 changed files with 138 additions and 27 deletions

View file

@ -139,7 +139,7 @@ trait SubchannelClassification { this: EventBus ⇒
val diff = subscriptions.addValue(to, subscriber)
if (diff.isEmpty) false
else {
cache = cache ++ diff
cache ++= diff
true
}
}
@ -148,16 +148,19 @@ trait SubchannelClassification { this: EventBus ⇒
val diff = subscriptions.removeValue(from, subscriber)
if (diff.isEmpty) false
else {
cache = cache ++ diff
removeFromCache(diff)
true
}
}
def unsubscribe(subscriber: Subscriber): Unit = subscriptions.synchronized {
val diff = subscriptions.removeValue(subscriber)
if (diff.nonEmpty) cache = cache ++ diff
if (diff.nonEmpty) removeFromCache(diff)
}
private def removeFromCache(changes: Seq[(Classifier, Set[Subscriber])]): Unit =
cache ++= changes map { case (c, s) (c, cache.getOrElse(c, Set[Subscriber]()) -- s) }
def publish(event: Event): Unit = {
val c = classify(event)
val recv =
@ -166,7 +169,7 @@ trait SubchannelClassification { this: EventBus ⇒
if (cache contains c) cache(c)
else {
val diff = subscriptions.addKey(c)
cache = cache ++ diff
cache ++= diff
cache(c)
}
}