Added load balancer which prefers actors with small mailboxes (discussed on mailing list a while ago).

This commit is contained in:
Jan Van Besien 2010-03-17 22:10:49 +01:00
parent c110b86b5c
commit 647bb9cc41
3 changed files with 44 additions and 1 deletions

View file

@ -73,4 +73,15 @@ class CyclicIterator[T](items: List[T]) extends InfiniteIterator[T] {
current = nc.tail
nc.head
}
}
}
class SmallestMailboxFirstIterator(items : List[Actor]) extends InfiniteIterator[Actor] {
def hasNext = items != Nil
def next = {
def actorWithSmallestMailbox(a1: Actor, a2: Actor) = {
if (a1.mailboxSize < a2.mailboxSize) a1 else a2
}
items.reduceLeft((actor1, actor2) => actorWithSmallestMailbox(actor1,actor2))
}
}