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:
commit
403369a29e
1 changed files with 6 additions and 5 deletions
|
|
@ -5,8 +5,6 @@ package akka.routing
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicLong
|
import java.util.concurrent.atomic.AtomicLong
|
||||||
import scala.collection.immutable
|
import scala.collection.immutable
|
||||||
import akka.actor.ActorContext
|
|
||||||
import akka.actor.Props
|
|
||||||
import akka.dispatch.Dispatchers
|
import akka.dispatch.Dispatchers
|
||||||
import com.typesafe.config.Config
|
import com.typesafe.config.Config
|
||||||
import akka.actor.SupervisorStrategy
|
import akka.actor.SupervisorStrategy
|
||||||
|
|
@ -23,11 +21,14 @@ object RoundRobinRoutingLogic {
|
||||||
*/
|
*/
|
||||||
@SerialVersionUID(1L)
|
@SerialVersionUID(1L)
|
||||||
final class RoundRobinRoutingLogic extends RoutingLogic {
|
final class RoundRobinRoutingLogic extends RoutingLogic {
|
||||||
val next = new AtomicLong(0)
|
val next = new AtomicLong
|
||||||
|
|
||||||
override def select(message: Any, routees: immutable.IndexedSeq[Routee]): Routee =
|
override def select(message: Any, routees: immutable.IndexedSeq[Routee]): Routee =
|
||||||
if (routees.isEmpty) NoRoutee
|
if (routees.nonEmpty) {
|
||||||
else routees((next.getAndIncrement % routees.size).asInstanceOf[Int])
|
val size = routees.size
|
||||||
|
val index = (next.getAndIncrement % size).asInstanceOf[Int]
|
||||||
|
routees(if (index < 0) size + index - 1 else index)
|
||||||
|
} else NoRoutee
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue