From 936436e6e39d7b454e8a402ddfe099c5adef8763 Mon Sep 17 00:00:00 2001 From: Guido Medina Date: Fri, 19 Jun 2015 17:52:13 +0100 Subject: [PATCH] =act #17738 RoundRobinRoutingLogic negative index fix after Long.MAX_VALUE (cherry picked from commit 8ef10c9c3d49fa431739ba8b234be5d54d528f1b) --- .../src/main/scala/akka/routing/RoundRobin.scala | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/akka-actor/src/main/scala/akka/routing/RoundRobin.scala b/akka-actor/src/main/scala/akka/routing/RoundRobin.scala index 71955ce552..868e9193fb 100644 --- a/akka-actor/src/main/scala/akka/routing/RoundRobin.scala +++ b/akka-actor/src/main/scala/akka/routing/RoundRobin.scala @@ -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 }