2011-12-15 18:19:40 +01:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2011 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
2011-12-15 15:28:21 +01:00
|
|
|
package akka.docs.routing
|
|
|
|
|
|
|
|
|
|
import akka.actor.ActorRef
|
|
|
|
|
|
|
|
|
|
//#boundedCapacitor
|
|
|
|
|
trait BoundedCapacitor {
|
|
|
|
|
def lowerBound: Int
|
|
|
|
|
def upperBound: Int
|
|
|
|
|
|
|
|
|
|
def capacity(delegates: Seq[ActorRef]): Int = {
|
|
|
|
|
val current = delegates length
|
|
|
|
|
var delta = _eval(delegates)
|
|
|
|
|
val proposed = current + delta
|
|
|
|
|
|
|
|
|
|
if (proposed < lowerBound) delta += (lowerBound - proposed)
|
|
|
|
|
else if (proposed > upperBound) delta -= (proposed - upperBound)
|
|
|
|
|
|
|
|
|
|
delta
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected def _eval(delegates: Seq[ActorRef]): Int
|
|
|
|
|
}
|
|
|
|
|
//#boundedCapacitor
|