Merge pull request #17907 from akka/wip-17738-round-robin-logic-neg-index-patriknw

=act #17738 RoundRobinRoutingLogic negative index fix after Long.MaxValue (for validation)
This commit is contained in:
Patrik Nordwall 2015-07-03 17:10:55 +02:00
commit 403369a29e

View file

@ -5,8 +5,6 @@ package akka.routing
import java.util.concurrent.atomic.AtomicLong
import scala.collection.immutable
import akka.actor.ActorContext
import akka.actor.Props
import akka.dispatch.Dispatchers
import com.typesafe.config.Config
import akka.actor.SupervisorStrategy
@ -23,11 +21,14 @@ object RoundRobinRoutingLogic {
*/
@SerialVersionUID(1L)
final class RoundRobinRoutingLogic extends RoutingLogic {
val next = new AtomicLong(0)
val next = new AtomicLong
override def select(message: Any, routees: immutable.IndexedSeq[Routee]): Routee =
if (routees.isEmpty) NoRoutee
else routees((next.getAndIncrement % routees.size).asInstanceOf[Int])
if (routees.nonEmpty) {
val size = routees.size
val index = (next.getAndIncrement % size).asInstanceOf[Int]
routees(if (index < 0) size + index - 1 else index)
} else NoRoutee
}