Skip to content

Commit

Permalink
Merge pull request akka#2070 from akka/wip-3843-singleton-proxy-sampl…
Browse files Browse the repository at this point in the history
…e-patriknw

=sam #3843 Use ClusterSingletonProxy in cluster samples
  • Loading branch information
patriknw committed Mar 17, 2014
2 parents 95d27e3 + ad18405 commit 3a9725f
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 173 deletions.
8 changes: 4 additions & 4 deletions akka-docs/rst/java/cluster-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,14 @@ in the contrib module. The ``ClusterSingletonManager`` is started on each node.
.. includecode:: ../../../akka-samples/akka-sample-cluster-java/src/main/java/sample/cluster/stats/StatsSampleOneMasterMain.java#create-singleton-manager

We also need an actor on each node that keeps track of where current single master exists and
delegates jobs to the ``StatsService``.
delegates jobs to the ``StatsService``. That is provided by the ``ClusterSingletonProxy``.

.. includecode:: ../../../akka-samples/akka-sample-cluster-java/src/main/java/sample/cluster/stats/StatsFacade.java#facade
.. includecode:: ../../../akka-samples/akka-sample-cluster-java/src/main/java/sample/cluster/stats/StatsSampleOneMasterMain.java#singleton-proxy

The ``StatsFacade`` receives text from users and delegates to the current ``StatsService``, the single
The ``ClusterSingletonProxy`` receives text from users and delegates to the current ``StatsService``, the single
master. It listens to cluster events to lookup the ``StatsService`` on the oldest node.

All nodes start ``StatsFacade`` and the ``ClusterSingletonManager``. The router is now configured like this:
All nodes start ``ClusterSingletonProxy`` and the ``ClusterSingletonManager``. The router is now configured like this:

.. includecode:: ../../../akka-samples/akka-sample-cluster-java/src/main/resources/stats2.conf#config-router-deploy

Expand Down
8 changes: 4 additions & 4 deletions akka-docs/rst/scala/cluster-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -514,14 +514,14 @@ in the contrib module. The ``ClusterSingletonManager`` is started on each node.
.. includecode:: ../../../akka-samples/akka-sample-cluster-scala/src/main/scala/sample/cluster/stats/StatsSampleOneMaster.scala#create-singleton-manager

We also need an actor on each node that keeps track of where current single master exists and
delegates jobs to the ``StatsService``.
delegates jobs to the ``StatsService``. That is provided by the ``ClusterSingletonProxy``.

.. includecode:: ../../../akka-samples/akka-sample-cluster-scala/src/main/scala/sample/cluster/stats/StatsFacade.scala#facade
.. includecode:: ../../../akka-samples/akka-sample-cluster-scala/src/main/scala/sample/cluster/stats/StatsSampleOneMaster.scala#singleton-proxy

The ``StatsFacade`` receives text from users and delegates to the current ``StatsService``, the single
The ``ClusterSingletonProxy`` receives text from users and delegates to the current ``StatsService``, the single
master. It listens to cluster events to lookup the ``StatsService`` on the oldest node.

All nodes start ``StatsFacade`` and the ``ClusterSingletonManager``. The router is now configured like this:
All nodes start ``ClusterSingletonProxy`` and the ``ClusterSingletonManager``. The router is now configured like this:

.. includecode:: ../../../akka-samples/akka-sample-cluster-scala/src/main/resources/stats2.conf#config-router-deploy

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static void main(String[] args) {
// note that client is not a compute node, role not defined
ActorSystem system = ActorSystem.create("ClusterSystem",
ConfigFactory.load("stats2"));
system.actorOf(Props.create(StatsSampleClient.class, "/user/statsFacade"),
system.actorOf(Props.create(StatsSampleClient.class, "/user/statsServiceProxy"),
"client");

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import akka.actor.PoisonPill;
import akka.actor.Props;
import akka.contrib.pattern.ClusterSingletonManager;
import akka.contrib.pattern.ClusterSingletonProxy;

public class StatsSampleOneMasterMain {

Expand Down Expand Up @@ -36,7 +37,10 @@ public static void startup(String[] ports) {
PoisonPill.getInstance(), "compute"), "singleton");
//#create-singleton-manager

system.actorOf(Props.create(StatsFacade.class), "statsFacade");
//#singleton-proxy
system.actorOf(ClusterSingletonProxy.defaultProps("/user/singleton/statsService",
"compute"), "statsServiceProxy");
//#singleton-proxy
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import akka.cluster.MemberStatus
import akka.cluster.ClusterEvent.CurrentClusterState
import akka.cluster.ClusterEvent.MemberUp
import akka.contrib.pattern.ClusterSingletonManager
import akka.contrib.pattern.ClusterSingletonProxy
import akka.remote.testkit.MultiNodeConfig
import akka.remote.testkit.MultiNodeSpec
import akka.testkit.ImplicitSender
Expand All @@ -35,7 +36,7 @@ object StatsSampleSingleMasterSpecConfig extends MultiNodeConfig {
akka.cluster.roles = [compute]
# don't use sigar for tests, native lib not in path
akka.cluster.metrics.collector-class = akka.cluster.JmxMetricsCollector
#//#router-deploy-config
#//#router-deploy-config
akka.actor.deployment {
/singleton/statsService/workerRouter {
router = consistent-hashing-pool
Expand All @@ -48,7 +49,7 @@ object StatsSampleSingleMasterSpecConfig extends MultiNodeConfig {
}
}
}
#//#router-deploy-config
#//#router-deploy-config
"""))

}
Expand Down Expand Up @@ -91,18 +92,19 @@ abstract class StatsSampleSingleMasterSpec extends MultiNodeSpec(StatsSampleSing
terminationMessage = PoisonPill,
role = null), name = "singleton")

system.actorOf(Props[StatsFacade], "statsFacade")
system.actorOf(ClusterSingletonProxy.defaultProps("/user/singleton/statsService",
"compute"), "statsServiceProxy");

testConductor.enter("all-up")
}

"show usage of the statsFacade" in within(40 seconds) {
val facade = system.actorSelection(RootActorPath(node(third).address) / "user" / "statsFacade")
"show usage of the statsServiceProxy" in within(40 seconds) {
val proxy = system.actorSelection(RootActorPath(node(third).address) / "user" / "statsServiceProxy")

// eventually the service should be ok,
// service and worker nodes might not be up yet
awaitAssert {
facade ! new StatsJob("this is the text that will be analyzed")
proxy ! new StatsJob("this is the text that will be analyzed")
expectMsgType[StatsResult](1.second).getMeanWordLength should be(3.875 +- 0.001)
}

Expand Down
7 changes: 3 additions & 4 deletions akka-samples/akka-sample-cluster-java/tutorial/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -352,17 +352,16 @@ <h2>Router Example with Pool of Remote Deployed Routees</h2>

<p>
We also need an actor on each node that keeps track of where current single master exists and
delegates jobs to the <code>StatsService</code>. That is handled by the
<a href="#code/src/main/java/sample/cluster/stats/StatsFacade.java" class="shortcut">StatsFacade.java</a>
delegates jobs to the <code>StatsService</code>. That is provided by the <code>ClusterSingletonProxy</code>.
</p>

<p>
The <code>StatsFacade</code> receives text from users and delegates to the current <code>StatsService</code>, the single
The <code>ClusterSingletonProxy</code> receives text from users and delegates to the current <code>StatsService</code>, the single
master. It listens to cluster events to lookup the <code>StatsService</code> on the oldest node.
</p>

<p>
All nodes start <code>StatsFacade</code> and the <code>ClusterSingletonManager</code>. The router is now configured in
All nodes start <code>ClusterSingletonProxy</code> and the <code>ClusterSingletonManager</code>. The router is now configured in
<a href="#code/src/main/resources/stats2.conf" class="shortcut">stats2.conf</a>
</p>

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import akka.actor.ActorSystem
import akka.actor.PoisonPill
import akka.actor.Props
import akka.contrib.pattern.ClusterSingletonManager
import akka.contrib.pattern.ClusterSingletonProxy

object StatsSampleOneMaster {
def main(args: Array[String]): Unit = {
Expand Down Expand Up @@ -32,7 +33,11 @@ object StatsSampleOneMaster {
terminationMessage = PoisonPill, role = Some("compute")),
name = "singleton")
//#create-singleton-manager
system.actorOf(Props[StatsFacade], name = "statsFacade")

//#singleton-proxy
system.actorOf(ClusterSingletonProxy.props(singletonPath = "/user/singleton/statsService",
role = Some("compute")), name = "statsServiceProxy")
//#singleton-proxy
}
}
}
Expand All @@ -41,7 +46,7 @@ object StatsSampleOneMasterClient {
def main(args: Array[String]): Unit = {
// note that client is not a compute node, role not defined
val system = ActorSystem("ClusterSystem")
system.actorOf(Props(classOf[StatsSampleClient], "/user/statsFacade"), "client")
system.actorOf(Props(classOf[StatsSampleClient], "/user/statsServiceProxy"), "client")
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import akka.actor.PoisonPill
import akka.actor.Props
import akka.actor.RootActorPath
import akka.contrib.pattern.ClusterSingletonManager
import akka.contrib.pattern.ClusterSingletonProxy
import akka.cluster.Cluster
import akka.cluster.Member
import akka.cluster.MemberStatus
Expand Down Expand Up @@ -88,18 +89,19 @@ abstract class StatsSampleSingleMasterSpec extends MultiNodeSpec(StatsSampleSing
singletonProps = Props[StatsService], singletonName = "statsService",
terminationMessage = PoisonPill, role = Some("compute")), name = "singleton")

system.actorOf(Props[StatsFacade], "statsFacade")
system.actorOf(ClusterSingletonProxy.props(singletonPath = "/user/singleton/statsService",
role = Some("compute")), name = "statsServiceProxy")

testConductor.enter("all-up")
}

"show usage of the statsFacade" in within(40 seconds) {
val facade = system.actorSelection(RootActorPath(node(third).address) / "user" / "statsFacade")
"show usage of the statsServiceProxy" in within(40 seconds) {
val proxy = system.actorSelection(RootActorPath(node(third).address) / "user" / "statsServiceProxy")

// eventually the service should be ok,
// service and worker nodes might not be up yet
awaitAssert {
facade ! StatsJob("this is the text that will be analyzed")
proxy ! StatsJob("this is the text that will be analyzed")
expectMsgType[StatsResult](1.second).meanWordLength should be(
3.875 +- 0.001)
}
Expand Down
7 changes: 3 additions & 4 deletions akka-samples/akka-sample-cluster-scala/tutorial/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -351,17 +351,16 @@ <h2>Router Example with Pool of Remote Deployed Routees</h2>

<p>
We also need an actor on each node that keeps track of where current single master exists and
delegates jobs to the <code>StatsService</code>. That is handled by the
<a href="#code/src/main/scala/sample/cluster/stats/StatsFacade.scala" class="shortcut">StatsFacade.scala</a>
delegates jobs to the <code>StatsService</code>. That is provided by the <code>ClusterSingletonProxy</code>.
</p>

<p>
The <code>StatsFacade</code> receives text from users and delegates to the current <code>StatsService</code>, the single
The <code>ClusterSingletonProxy</code> receives text from users and delegates to the current <code>StatsService</code>, the single
master. It listens to cluster events to lookup the <code>StatsService</code> on the oldest node.
</p>

<p>
All nodes start <code>StatsFacade</code> and the <code>ClusterSingletonManager</code>. The router is now configured in
All nodes start <code>ClusterSingletonProxy</code> and the <code>ClusterSingletonManager</code>. The router is now configured in
<a href="#code/src/main/resources/stats2.conf" class="shortcut">stats2.conf</a>
</p>

Expand Down

0 comments on commit 3a9725f

Please sign in to comment.