-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreationApplication.scala
38 lines (32 loc) · 1.12 KB
/
CreationApplication.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
package sample.remote.calculator
import scala.concurrent.duration._
import com.typesafe.config.ConfigFactory
import scala.util.Random
import akka.actor.ActorSystem
import akka.actor.Props
object CreationApplication {
def main(args: Array[String]): Unit = {
if (args.isEmpty || args.head == "CalculatorWorker")
startRemoteWorkerSystem()
if (args.isEmpty || args.head == "Creation")
startRemoteCreationSystem()
}
def startRemoteWorkerSystem(): Unit = {
ActorSystem("CalculatorWorkerSystem", ConfigFactory.load("calculator"))
println("Started CalculatorWorkerSystem")
}
def startRemoteCreationSystem(): Unit = {
val system =
ActorSystem("CreationSystem", ConfigFactory.load("remotecreation"))
val actor = system.actorOf(Props[CreationActor],
name = "creationActor")
println("Started CreationSystem")
import system.dispatcher
system.scheduler.schedule(1.second, 1.second) {
if (Random.nextInt(100) % 2 == 0)
actor ! Multiply(Random.nextInt(20), Random.nextInt(20))
else
actor ! Divide(Random.nextInt(10000), (Random.nextInt(99) + 1))
}
}
}