diff --git a/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala b/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala index 0de41a24d7..cffd7776c4 100644 --- a/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala @@ -373,12 +373,12 @@ class RoutingSpec extends AkkaSpec with DefaultTimeout with ImplicitSender { "custom router" must { "be started when constructed" in { - val routedActor = system.actorOf(Props[TestActor].withRouter(VoteCountRouter())) + val routedActor = system.actorOf(Props[TestActor].withRouter(new VoteCountRouter)) routedActor.isTerminated must be(false) } "count votes as intended - not as in Florida" in { - val routedActor = system.actorOf(Props[TestActor].withRouter(VoteCountRouter())) + val routedActor = system.actorOf(Props[TestActor].withRouter(new VoteCountRouter)) routedActor ! DemocratVote routedActor ! DemocratVote routedActor ! RepublicanVote @@ -422,11 +422,7 @@ class RoutingSpec extends AkkaSpec with DefaultTimeout with ImplicitSender { //#crActors //#crRouter - case class VoteCountRouter( - nrOfInstances: Int = 0, - routees: Iterable[String] = Nil, - within: Duration = Duration.Zero) - extends RouterConfig { + class VoteCountRouter extends RouterConfig { //#crRoute def createRoute(props: Props, diff --git a/akka-actor/src/main/scala/akka/routing/Routing.scala b/akka-actor/src/main/scala/akka/routing/Routing.scala index b4f3709e66..1d0de394cf 100644 --- a/akka-actor/src/main/scala/akka/routing/Routing.scala +++ b/akka-actor/src/main/scala/akka/routing/Routing.scala @@ -79,12 +79,6 @@ private[akka] class RoutedActorRef(_system: ActorSystemImpl, _props: Props, _sup */ trait RouterConfig { - def nrOfInstances: Int - - def routees: Iterable[String] - - def within: Duration - def createRoute(props: Props, actorContext: ActorContext, ref: RoutedActorRef): Route def createActor(): Router = new Router {} @@ -173,9 +167,8 @@ case class Destination(sender: ActorRef, recipient: ActorRef) * Oxymoron style. */ case object NoRouter extends RouterConfig { - def nrOfInstances = 0 - def routees = Nil - def within = Duration.Zero + def nrOfInstances: Int = 0 + def routees: Iterable[String] = Nil def createRoute(props: Props, actorContext: ActorContext, ref: RoutedActorRef): Route = null } @@ -193,7 +186,7 @@ object RoundRobinRouter { * if you provide either 'nrOfInstances' or 'routees' to during instantiation they will * be ignored if the 'nrOfInstances' is defined in the configuration file for the actor being used. */ -case class RoundRobinRouter(nrOfInstances: Int = 0, routees: Iterable[String] = Nil, within: Duration = Duration.Zero) extends RouterConfig with RoundRobinLike { +case class RoundRobinRouter(nrOfInstances: Int = 0, routees: Iterable[String] = Nil) extends RouterConfig with RoundRobinLike { /** * Constructor that sets nrOfInstances to be created. @@ -213,6 +206,11 @@ case class RoundRobinRouter(nrOfInstances: Int = 0, routees: Iterable[String] = } trait RoundRobinLike { this: RouterConfig ⇒ + + val nrOfInstances: Int + + val routees: Iterable[String] + def createRoute(props: Props, context: ActorContext, ref: RoutedActorRef): Route = { createAndRegisterRoutees(props, context, nrOfInstances, routees) @@ -246,7 +244,7 @@ object RandomRouter { * if you provide either 'nrOfInstances' or 'routees' to during instantiation they will * be ignored if the 'nrOfInstances' is defined in the configuration file for the actor being used. */ -case class RandomRouter(nrOfInstances: Int = 0, routees: Iterable[String] = Nil, within: Duration = Duration.Zero) extends RouterConfig with RandomLike { +case class RandomRouter(nrOfInstances: Int = 0, routees: Iterable[String] = Nil) extends RouterConfig with RandomLike { /** * Constructor that sets nrOfInstances to be created. @@ -269,6 +267,10 @@ trait RandomLike { this: RouterConfig ⇒ import java.security.SecureRandom + val nrOfInstances: Int + + val routees: Iterable[String] + private val random = new ThreadLocal[SecureRandom] { override def initialValue = SecureRandom.getInstance("SHA1PRNG") } @@ -304,7 +306,7 @@ object BroadcastRouter { * if you provide either 'nrOfInstances' or 'routees' to during instantiation they will * be ignored if the 'nrOfInstances' is defined in the configuration file for the actor being used. */ -case class BroadcastRouter(nrOfInstances: Int = 0, routees: Iterable[String] = Nil, within: Duration = Duration.Zero) extends RouterConfig with BroadcastLike { +case class BroadcastRouter(nrOfInstances: Int = 0, routees: Iterable[String] = Nil) extends RouterConfig with BroadcastLike { /** * Constructor that sets nrOfInstances to be created. @@ -324,6 +326,11 @@ case class BroadcastRouter(nrOfInstances: Int = 0, routees: Iterable[String] = N } trait BroadcastLike { this: RouterConfig ⇒ + + val nrOfInstances: Int + + val routees: Iterable[String] + def createRoute(props: Props, context: ActorContext, ref: RoutedActorRef): Route = { createAndRegisterRoutees(props, context, nrOfInstances, routees) @@ -371,6 +378,13 @@ case class ScatterGatherFirstCompletedRouter(nrOfInstances: Int = 0, routees: It } trait ScatterGatherFirstCompletedLike { this: RouterConfig ⇒ + + val nrOfInstances: Int + + val routees: Iterable[String] + + val within: Duration + def createRoute(props: Props, context: ActorContext, ref: RoutedActorRef): Route = { createAndRegisterRoutees(props, context, nrOfInstances, routees) diff --git a/akka-remote/src/main/scala/akka/remote/RemoteDeployer.scala b/akka-remote/src/main/scala/akka/remote/RemoteDeployer.scala index ee712d8804..a7836c187d 100644 --- a/akka-remote/src/main/scala/akka/remote/RemoteDeployer.scala +++ b/akka-remote/src/main/scala/akka/remote/RemoteDeployer.scala @@ -26,9 +26,9 @@ class RemoteDeployer(_settings: ActorSystem.Settings) extends Deployer(_settings if (nodes.isEmpty || deploy.routing == NoRouter) d else { val r = deploy.routing match { - case RoundRobinRouter(x, _, w) ⇒ RemoteRoundRobinRouter(x, nodes, w) - case RandomRouter(x, _, w) ⇒ RemoteRandomRouter(x, nodes, w) - case BroadcastRouter(x, _, w) ⇒ RemoteBroadcastRouter(x, nodes, w) + case RoundRobinRouter(x, _) ⇒ RemoteRoundRobinRouter(x, nodes) + case RandomRouter(x, _) ⇒ RemoteRandomRouter(x, nodes) + case BroadcastRouter(x, _) ⇒ RemoteBroadcastRouter(x, nodes) case ScatterGatherFirstCompletedRouter(x, _, w) ⇒ RemoteScatterGatherFirstCompletedRouter(x, nodes, w) } Some(deploy.copy(routing = r)) diff --git a/akka-remote/src/main/scala/akka/routing/RemoteRouters.scala b/akka-remote/src/main/scala/akka/routing/RemoteRouters.scala index 42af714d63..748e3694bb 100644 --- a/akka-remote/src/main/scala/akka/routing/RemoteRouters.scala +++ b/akka-remote/src/main/scala/akka/routing/RemoteRouters.scala @@ -39,13 +39,13 @@ trait RemoteRouterConfig extends RouterConfig { * if you provide either 'nrOfInstances' or 'routees' to during instantiation they will * be ignored if the 'nrOfInstances' is defined in the configuration file for the actor being used. */ -case class RemoteRoundRobinRouter(nrOfInstances: Int, routees: Iterable[String], within: Duration) extends RemoteRouterConfig with RoundRobinLike { +case class RemoteRoundRobinRouter(nrOfInstances: Int, routees: Iterable[String]) extends RemoteRouterConfig with RoundRobinLike { /** * Constructor that sets the routees to be used. * Java API */ - def this(n: Int, t: java.util.Collection[String], w: Duration) = this(n, t.asScala, w) + def this(n: Int, t: java.util.Collection[String]) = this(n, t.asScala) } /** @@ -59,13 +59,13 @@ case class RemoteRoundRobinRouter(nrOfInstances: Int, routees: Iterable[String], * if you provide either 'nrOfInstances' or 'routees' to during instantiation they will * be ignored if the 'nrOfInstances' is defined in the configuration file for the actor being used. */ -case class RemoteRandomRouter(nrOfInstances: Int, routees: Iterable[String], within: Duration) extends RemoteRouterConfig with RandomLike { +case class RemoteRandomRouter(nrOfInstances: Int, routees: Iterable[String]) extends RemoteRouterConfig with RandomLike { /** * Constructor that sets the routees to be used. * Java API */ - def this(n: Int, t: java.util.Collection[String], w: Duration) = this(n, t.asScala, w) + def this(n: Int, t: java.util.Collection[String]) = this(n, t.asScala) } /** @@ -79,13 +79,13 @@ case class RemoteRandomRouter(nrOfInstances: Int, routees: Iterable[String], wit * if you provide either 'nrOfInstances' or 'routees' to during instantiation they will * be ignored if the 'nrOfInstances' is defined in the configuration file for the actor being used. */ -case class RemoteBroadcastRouter(nrOfInstances: Int, routees: Iterable[String], within: Duration) extends RemoteRouterConfig with BroadcastLike { +case class RemoteBroadcastRouter(nrOfInstances: Int, routees: Iterable[String]) extends RemoteRouterConfig with BroadcastLike { /** * Constructor that sets the routees to be used. * Java API */ - def this(n: Int, t: java.util.Collection[String], w: Duration) = this(n, t.asScala, w) + def this(n: Int, t: java.util.Collection[String]) = this(n, t.asScala) } /**