-
Notifications
You must be signed in to change notification settings - Fork 0
/
KVAppService.scala
47 lines (34 loc) · 1.61 KB
/
KVAppService.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package rings
import akka.actor.{ActorSystem, ActorRef, Props}
sealed trait AppServiceAPI
case class Prime() extends AppServiceAPI
case class Command() extends AppServiceAPI
case class View(lockClients: Seq[ActorRef]) extends AppServiceAPI
/**
* This object instantiates the service tiers and a load-generating master, and
* links all the actors together by passing around ActorRef references.
*
* The service to instantiate is bolted into the KVAppService code. Modify this
* object if you want to instantiate a different service.
*/
object KVAppService {
def apply(system: ActorSystem, numNodes: Int, ackEach: Int, t: Int): ActorRef = {
/** Lock tier: create lock clients and lock server*/
val lockServer = system.actorOf(LockServer.props(system, t), "LockServer")
/** Service tier: create app servers */
val servers = for (i <- 0 to numNodes-1)
yield system.actorOf(GroupServer.props(lockServer, t, i, ackEach), "GroupServer" + i)
lockServer ! View(servers)
/** If you want to initialize a different service instead, that previous line might look like this:
* yield system.actorOf(GroupServer.props(i, numNodes, stores, ackEach), "GroupServer" + i)
* For that you need to implement the GroupServer object and the companion actor class.
* Following the "rings" example.
*/
// /** Tells each server the list of servers and their ActorRefs wrapped in a message. */
// for (server <- servers)
// server ! View(lock_server)
/** Load-generating master */
val master = system.actorOf(LoadMaster.props(numNodes, servers, ackEach), "LoadMaster")
master
}
}