From 04a72b6cd8fa3a3393f206aaeeeabef83743c642 Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Wed, 16 Mar 2011 19:31:54 +0100 Subject: [PATCH] ActorPool code cleanup, fixing some qmarks and some minor defects --- .../src/main/scala/akka/routing/Pool.scala | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/akka-actor/src/main/scala/akka/routing/Pool.scala b/akka-actor/src/main/scala/akka/routing/Pool.scala index a468e4b37f..be854928d8 100644 --- a/akka-actor/src/main/scala/akka/routing/Pool.scala +++ b/akka-actor/src/main/scala/akka/routing/Pool.scala @@ -117,11 +117,10 @@ trait SmallestMailboxSelector { def select(delegates: Seq[ActorRef]): Tuple2[Iterator[ActorRef], Int] = { var set: Seq[ActorRef] = Nil - var take = if (partialFill) math.min(selectionCount, delegates.length) - else selectionCount + var take = if (partialFill) math.min(selectionCount, delegates.length) else selectionCount while (take > 0) { - set = delegates.sortWith((a,b) => a.mailboxSize < b.mailboxSize).take(take) ++ set + set = delegates.sortWith(_.mailboxSize < _.mailboxSize).take(take) ++ set //Question, doesn't this risk selecting the same actor multiple times? take -= set.size } @@ -164,11 +163,7 @@ trait RoundRobinSelector { */ trait FixedSizeCapacitor { def limit:Int - - def capacity(delegates: Seq[ActorRef]): Int = (limit - delegates.size) match { - case i if i > 0 => i - case _ => 0 - } + def capacity(delegates: Seq[ActorRef]): Int = (limit - delegates.size) max 0 } /** @@ -288,13 +283,14 @@ trait RunningMeanBackoff { _pressure += pressure _capacity += capacity - if (capacity > 0 && pressure / capacity < backoffThreshold && _capacity > 0 && _pressure / _capacity < backoffThreshold) + if (capacity > 0 && pressure / capacity < backoffThreshold + && _capacity > 0 && _pressure / _capacity < backoffThreshold) //Why does the entire clause need to be true? math.floor(-1.0 * backoffRate * (capacity-pressure)).toInt else 0 } - def backoffReset = { - _pressure - 0.0 + def backoffReset { + _pressure = 0.0 _capacity = 0.0 } }