Deploy not needed for programatically defined cluster router, see #2103
* This also removes the need for the withClusterRouter sugar * Improved the apply and constructors for ClusterRouterSettings, since that will be user api instead
This commit is contained in:
parent
2e537af78a
commit
7cf6ab54c8
4 changed files with 51 additions and 87 deletions
|
|
@ -70,11 +70,51 @@ case class ClusterRouterConfig(local: RouterConfig, settings: ClusterRouterSetti
|
|||
}
|
||||
}
|
||||
|
||||
case class ClusterRouterSettings(
|
||||
object ClusterRouterSettings {
|
||||
/**
|
||||
* Settings for create and deploy of the routees
|
||||
*/
|
||||
def apply(totalInstances: Int, maxInstancesPerNode: Int, routeesOnOwnNode: Boolean): ClusterRouterSettings =
|
||||
new ClusterRouterSettings(totalInstances, maxInstancesPerNode, routeesOnOwnNode)
|
||||
|
||||
/**
|
||||
* Settings for remote deployment of the routees, allowed to use routees on own node
|
||||
*/
|
||||
def apply(totalInstances: Int, maxInstancesPerNode: Int): ClusterRouterSettings =
|
||||
apply(totalInstances, maxInstancesPerNode, routeesOnOwnNode = true)
|
||||
|
||||
/**
|
||||
* Settings for lookup of the routees
|
||||
*/
|
||||
def apply(totalInstances: Int, routeesPath: String, routeesOnOwnNode: Boolean): ClusterRouterSettings =
|
||||
new ClusterRouterSettings(totalInstances, routeesPath, routeesOnOwnNode)
|
||||
|
||||
/**
|
||||
* Settings for lookup of the routees, allowed to use routees on own node
|
||||
*/
|
||||
def apply(totalInstances: Int, routeesPath: String): ClusterRouterSettings =
|
||||
apply(totalInstances, routeesPath, routeesOnOwnNode = true)
|
||||
}
|
||||
|
||||
case class ClusterRouterSettings private[akka] (
|
||||
totalInstances: Int,
|
||||
maxInstancesPerNode: Int = 1,
|
||||
routeesOnOwnNode: Boolean = true,
|
||||
routeesPath: String = "") {
|
||||
maxInstancesPerNode: Int,
|
||||
routeesPath: String,
|
||||
routeesOnOwnNode: Boolean) {
|
||||
|
||||
/**
|
||||
* Settings for create and deploy of the routees
|
||||
* JAVA API
|
||||
*/
|
||||
def this(totalInstances: Int, maxInstancesPerNode: Int, routeesOnOwnNode: Boolean) =
|
||||
this(totalInstances, maxInstancesPerNode, routeesPath = "", routeesOnOwnNode)
|
||||
|
||||
/**
|
||||
* Settings for lookup of the routees
|
||||
* JAVA API
|
||||
*/
|
||||
def this(totalInstances: Int, routeesPath: String, routeesOnOwnNode: Boolean) =
|
||||
this(totalInstances, maxInstancesPerNode = 1, routeesPath, routeesOnOwnNode)
|
||||
|
||||
if (totalInstances <= 0) throw new IllegalArgumentException("totalInstances of cluster router must be > 0")
|
||||
if (maxInstancesPerNode <= 0) throw new IllegalArgumentException("maxInstancesPerNode of cluster router must be > 0")
|
||||
|
|
@ -221,32 +261,3 @@ private[akka] class ClusterRouterActor extends Router {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sugar to define cluster aware router programatically.
|
||||
* Java API.
|
||||
* When creating and deploying routees:
|
||||
* [[[
|
||||
* context.actorOf(ClusterRouterPropsDecorator.decorate(new Props(MyActor.class),
|
||||
* new RoundRobinRouter(0), 10, 2), "myrouter");
|
||||
* ]]]
|
||||
* When looking up routees:
|
||||
* [[[
|
||||
* context.actorOf(ClusterRouterPropsDecorator.decorate(new Props(MyActor.class),
|
||||
* new RoundRobinRouter(0), 10, "/user/myservice"), "myrouter");
|
||||
* ]]]
|
||||
*
|
||||
* Corresponding for Scala API is found in [[akka.cluster.routing.ClusterRouterProps]].
|
||||
*
|
||||
*/
|
||||
object ClusterRouterPropsDecorator {
|
||||
def decorate(props: Props, router: RouterConfig, totalInstances: Int, maxInstancesPerNode: Int): Props =
|
||||
decorate(props, router, ClusterRouterSettings(totalInstances, maxInstancesPerNode))
|
||||
|
||||
def decorate(props: Props, router: RouterConfig, totalInstances: Int, routeesPath: String): Props =
|
||||
decorate(props, router, ClusterRouterSettings(totalInstances, routeesPath = routeesPath))
|
||||
|
||||
def decorate(props: Props, router: RouterConfig, settings: ClusterRouterSettings): Props =
|
||||
props.withClusterRouter(router, settings)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
|
||||
package akka.cluster
|
||||
|
||||
import language.implicitConversions
|
||||
import akka.actor.Deploy
|
||||
import akka.actor.Props
|
||||
import akka.routing.RouterConfig
|
||||
|
||||
package object routing {
|
||||
|
||||
/**
|
||||
* Sugar to define cluster aware router programatically.
|
||||
*
|
||||
* When creating and deploying routees:
|
||||
* [[[
|
||||
* import akka.cluster.routing.ClusterRouterProps
|
||||
* context.actorOf(Props[SomeActor].withClusterRouter(RoundRobinRouter(),
|
||||
* totalInstances = 10, maxInstancesPerNode = 2), "myrouter")
|
||||
* ]]]
|
||||
*
|
||||
* When looking up routees:
|
||||
* [[[
|
||||
* import akka.cluster.routing.ClusterRouterProps
|
||||
* context.actorOf(Props[SomeActor].withClusterRouter(RoundRobinRouter(),
|
||||
* totalInstances = 10, routeesPath = "/user/myservice"), "myrouter")
|
||||
* ]]]
|
||||
*
|
||||
* Corresponding for Java API is found in [[akka.cluster.routing.ClusterRouterPropsDecorator]].
|
||||
*/
|
||||
implicit class ClusterRouterProps(val props: Props) extends AnyVal {
|
||||
|
||||
def withClusterRouter(router: RouterConfig, totalInstances: Int, maxInstancesPerNode: Int): Props =
|
||||
withClusterRouter(router, ClusterRouterSettings(totalInstances, maxInstancesPerNode))
|
||||
|
||||
def withClusterRouter(router: RouterConfig, totalInstances: Int, routeesPath: String): Props =
|
||||
withClusterRouter(router, ClusterRouterSettings(totalInstances, routeesPath = routeesPath))
|
||||
|
||||
def withClusterRouter(router: RouterConfig, settings: ClusterRouterSettings): Props = {
|
||||
props.withRouter(router).withDeploy(
|
||||
Deploy(routerConfig = ClusterRouterConfig(router, settings)))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -88,11 +88,8 @@ abstract class ClusterRoundRobinRoutedActorSpec extends MultiNodeSpec(ClusterRou
|
|||
import ClusterRoundRobinRoutedActorMultiJvmSpec._
|
||||
|
||||
lazy val router1 = system.actorOf(Props[SomeActor].withRouter(RoundRobinRouter()), "router1")
|
||||
lazy val router2 = {
|
||||
import akka.cluster.routing.ClusterRouterProps
|
||||
system.actorOf(Props[SomeActor].withClusterRouter(RoundRobinRouter(),
|
||||
totalInstances = 3, maxInstancesPerNode = 1), "router2")
|
||||
}
|
||||
lazy val router2 = system.actorOf(Props[SomeActor].withRouter(ClusterRouterConfig(RoundRobinRouter(),
|
||||
ClusterRouterSettings(totalInstances = 3, maxInstancesPerNode = 1))), "router2")
|
||||
lazy val router3 = system.actorOf(Props[SomeActor].withRouter(RoundRobinRouter()), "router3")
|
||||
lazy val router4 = system.actorOf(Props[SomeActor].withRouter(RoundRobinRouter()), "router4")
|
||||
|
||||
|
|
@ -275,5 +272,6 @@ abstract class ClusterRoundRobinRoutedActorSpec extends MultiNodeSpec(ClusterRou
|
|||
|
||||
enterBarrier("after-8")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,8 @@ class ClusterDeployerSpec extends AkkaSpec(ClusterDeployerSpec.deployerConf) {
|
|||
Deploy(
|
||||
service,
|
||||
deployment.get.config,
|
||||
ClusterRouterConfig(RoundRobinRouter(20), ClusterRouterSettings(20, 3, false, "")),
|
||||
ClusterRouterConfig(RoundRobinRouter(20), ClusterRouterSettings(
|
||||
totalInstances = 20, maxInstancesPerNode = 3, routeesOnOwnNode = false)),
|
||||
ClusterScope)))
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +66,8 @@ class ClusterDeployerSpec extends AkkaSpec(ClusterDeployerSpec.deployerConf) {
|
|||
Deploy(
|
||||
service,
|
||||
deployment.get.config,
|
||||
ClusterRouterConfig(RoundRobinRouter(20), ClusterRouterSettings(20, 1, false, "/user/myservice")),
|
||||
ClusterRouterConfig(RoundRobinRouter(20), ClusterRouterSettings(
|
||||
totalInstances = 20, routeesPath = "/user/myservice", routeesOnOwnNode = false)),
|
||||
ClusterScope)))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue