Switching to TreeSet, which should also receive quite some performance enhancements in Scala 2.10
This commit is contained in:
parent
807843591c
commit
ef399e283d
1 changed files with 14 additions and 13 deletions
|
|
@ -9,6 +9,7 @@ import akka.util.Index
|
|||
import java.util.concurrent.ConcurrentSkipListSet
|
||||
import java.util.Comparator
|
||||
import akka.util.{ Subclassification, SubclassifiedIndex }
|
||||
import collection.immutable.TreeSet
|
||||
|
||||
/**
|
||||
* Represents the base type for EventBuses
|
||||
|
|
@ -236,8 +237,8 @@ trait ScanningClassification { self: EventBus ⇒
|
|||
trait ActorClassification { this: ActorEventBus with ActorClassifier ⇒
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import scala.annotation.tailrec
|
||||
|
||||
protected val mappings = new ConcurrentHashMap[ActorRef, Vector[ActorRef]](mapSize)
|
||||
private val empty = TreeSet.empty[ActorRef]
|
||||
protected val mappings = new ConcurrentHashMap[ActorRef, TreeSet[ActorRef]](mapSize)
|
||||
|
||||
@tailrec
|
||||
protected final def associate(monitored: ActorRef, monitor: ActorRef): Boolean = {
|
||||
|
|
@ -246,15 +247,15 @@ trait ActorClassification { this: ActorEventBus with ActorClassifier ⇒
|
|||
case null ⇒
|
||||
if (monitored.isTerminated) false
|
||||
else {
|
||||
if (mappings.putIfAbsent(monitored, Vector(monitor)) ne null) associate(monitored, monitor)
|
||||
if (mappings.putIfAbsent(monitored, TreeSet(monitor)) ne null) associate(monitored, monitor)
|
||||
else if (monitored.isTerminated) !dissociate(monitored, monitor) else true
|
||||
}
|
||||
case raw: Vector[_] ⇒
|
||||
val v = raw.asInstanceOf[Vector[ActorRef]]
|
||||
case raw: TreeSet[_] ⇒
|
||||
val v = raw.asInstanceOf[TreeSet[ActorRef]]
|
||||
if (monitored.isTerminated) false
|
||||
if (v.contains(monitor)) true
|
||||
else {
|
||||
val added = v :+ monitor
|
||||
val added = v + monitor
|
||||
if (!mappings.replace(monitored, v, added)) associate(monitored, monitor)
|
||||
else if (monitored.isTerminated) !dissociate(monitored, monitor) else true
|
||||
}
|
||||
|
|
@ -266,9 +267,9 @@ trait ActorClassification { this: ActorEventBus with ActorClassifier ⇒
|
|||
def dissociateAsMonitored(monitored: ActorRef): Iterable[ActorRef] = {
|
||||
val current = mappings get monitored
|
||||
current match {
|
||||
case null ⇒ Vector.empty[ActorRef]
|
||||
case raw: Vector[_] ⇒
|
||||
val v = raw.asInstanceOf[Vector[ActorRef]]
|
||||
case null ⇒ empty
|
||||
case raw: TreeSet[_] ⇒
|
||||
val v = raw.asInstanceOf[TreeSet[ActorRef]]
|
||||
if (!mappings.remove(monitored, v)) dissociateAsMonitored(monitored)
|
||||
else v
|
||||
}
|
||||
|
|
@ -280,8 +281,8 @@ trait ActorClassification { this: ActorEventBus with ActorClassifier ⇒
|
|||
val entry = i.next()
|
||||
val v = entry.getValue
|
||||
v match {
|
||||
case raw: Vector[_] ⇒
|
||||
val monitors = raw.asInstanceOf[Vector[ActorRef]]
|
||||
case raw: TreeSet[_] ⇒
|
||||
val monitors = raw.asInstanceOf[TreeSet[ActorRef]]
|
||||
if (monitors.contains(monitor))
|
||||
dissociate(entry.getKey, monitor)
|
||||
case _ ⇒ //Dun care
|
||||
|
|
@ -297,8 +298,8 @@ trait ActorClassification { this: ActorEventBus with ActorClassifier ⇒
|
|||
val current = mappings get monitored
|
||||
current match {
|
||||
case null ⇒ false
|
||||
case raw: Vector[_] ⇒
|
||||
val v = raw.asInstanceOf[Vector[ActorRef]]
|
||||
case raw: TreeSet[_] ⇒
|
||||
val v = raw.asInstanceOf[TreeSet[ActorRef]]
|
||||
val removed = v.filterNot(monitor ==)
|
||||
if (removed eq raw) false
|
||||
else if (removed.isEmpty) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue