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.concurrent.ConcurrentSkipListSet
|
||||||
import java.util.Comparator
|
import java.util.Comparator
|
||||||
import akka.util.{ Subclassification, SubclassifiedIndex }
|
import akka.util.{ Subclassification, SubclassifiedIndex }
|
||||||
|
import collection.immutable.TreeSet
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the base type for EventBuses
|
* Represents the base type for EventBuses
|
||||||
|
|
@ -236,8 +237,8 @@ trait ScanningClassification { self: EventBus ⇒
|
||||||
trait ActorClassification { this: ActorEventBus with ActorClassifier ⇒
|
trait ActorClassification { this: ActorEventBus with ActorClassifier ⇒
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import scala.annotation.tailrec
|
import scala.annotation.tailrec
|
||||||
|
private val empty = TreeSet.empty[ActorRef]
|
||||||
protected val mappings = new ConcurrentHashMap[ActorRef, Vector[ActorRef]](mapSize)
|
protected val mappings = new ConcurrentHashMap[ActorRef, TreeSet[ActorRef]](mapSize)
|
||||||
|
|
||||||
@tailrec
|
@tailrec
|
||||||
protected final def associate(monitored: ActorRef, monitor: ActorRef): Boolean = {
|
protected final def associate(monitored: ActorRef, monitor: ActorRef): Boolean = {
|
||||||
|
|
@ -246,15 +247,15 @@ trait ActorClassification { this: ActorEventBus with ActorClassifier ⇒
|
||||||
case null ⇒
|
case null ⇒
|
||||||
if (monitored.isTerminated) false
|
if (monitored.isTerminated) false
|
||||||
else {
|
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
|
else if (monitored.isTerminated) !dissociate(monitored, monitor) else true
|
||||||
}
|
}
|
||||||
case raw: Vector[_] ⇒
|
case raw: TreeSet[_] ⇒
|
||||||
val v = raw.asInstanceOf[Vector[ActorRef]]
|
val v = raw.asInstanceOf[TreeSet[ActorRef]]
|
||||||
if (monitored.isTerminated) false
|
if (monitored.isTerminated) false
|
||||||
if (v.contains(monitor)) true
|
if (v.contains(monitor)) true
|
||||||
else {
|
else {
|
||||||
val added = v :+ monitor
|
val added = v + monitor
|
||||||
if (!mappings.replace(monitored, v, added)) associate(monitored, monitor)
|
if (!mappings.replace(monitored, v, added)) associate(monitored, monitor)
|
||||||
else if (monitored.isTerminated) !dissociate(monitored, monitor) else true
|
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] = {
|
def dissociateAsMonitored(monitored: ActorRef): Iterable[ActorRef] = {
|
||||||
val current = mappings get monitored
|
val current = mappings get monitored
|
||||||
current match {
|
current match {
|
||||||
case null ⇒ Vector.empty[ActorRef]
|
case null ⇒ empty
|
||||||
case raw: Vector[_] ⇒
|
case raw: TreeSet[_] ⇒
|
||||||
val v = raw.asInstanceOf[Vector[ActorRef]]
|
val v = raw.asInstanceOf[TreeSet[ActorRef]]
|
||||||
if (!mappings.remove(monitored, v)) dissociateAsMonitored(monitored)
|
if (!mappings.remove(monitored, v)) dissociateAsMonitored(monitored)
|
||||||
else v
|
else v
|
||||||
}
|
}
|
||||||
|
|
@ -280,8 +281,8 @@ trait ActorClassification { this: ActorEventBus with ActorClassifier ⇒
|
||||||
val entry = i.next()
|
val entry = i.next()
|
||||||
val v = entry.getValue
|
val v = entry.getValue
|
||||||
v match {
|
v match {
|
||||||
case raw: Vector[_] ⇒
|
case raw: TreeSet[_] ⇒
|
||||||
val monitors = raw.asInstanceOf[Vector[ActorRef]]
|
val monitors = raw.asInstanceOf[TreeSet[ActorRef]]
|
||||||
if (monitors.contains(monitor))
|
if (monitors.contains(monitor))
|
||||||
dissociate(entry.getKey, monitor)
|
dissociate(entry.getKey, monitor)
|
||||||
case _ ⇒ //Dun care
|
case _ ⇒ //Dun care
|
||||||
|
|
@ -297,8 +298,8 @@ trait ActorClassification { this: ActorEventBus with ActorClassifier ⇒
|
||||||
val current = mappings get monitored
|
val current = mappings get monitored
|
||||||
current match {
|
current match {
|
||||||
case null ⇒ false
|
case null ⇒ false
|
||||||
case raw: Vector[_] ⇒
|
case raw: TreeSet[_] ⇒
|
||||||
val v = raw.asInstanceOf[Vector[ActorRef]]
|
val v = raw.asInstanceOf[TreeSet[ActorRef]]
|
||||||
val removed = v.filterNot(monitor ==)
|
val removed = v.filterNot(monitor ==)
|
||||||
if (removed eq raw) false
|
if (removed eq raw) false
|
||||||
else if (removed.isEmpty) {
|
else if (removed.isEmpty) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue