|
Akka/Scala example source code file (LookupApplication.scala)
The LookupApplication.scala Akka example source code
package sample.remote.calculator
import scala.concurrent.duration._
import scala.util.Random
import com.typesafe.config.ConfigFactory
import akka.actor.ActorSystem
import akka.actor.Props
object LookupApplication {
def main(args: Array[String]): Unit = {
if (args.isEmpty || args.head == "Calculator")
startRemoteCalculatorSystem()
if (args.isEmpty || args.head == "Lookup")
startRemoteLookupSystem()
}
def startRemoteCalculatorSystem(): Unit = {
val system = ActorSystem("CalculatorSystem",
ConfigFactory.load("calculator"))
system.actorOf(Props[CalculatorActor], "calculator")
println("Started CalculatorSystem - waiting for messages")
}
def startRemoteLookupSystem(): Unit = {
val system =
ActorSystem("LookupSystem", ConfigFactory.load("remotelookup"))
val remotePath =
"akka.tcp://CalculatorSystem@127.0.0.1:2552/user/calculator"
val actor = system.actorOf(Props(classOf[LookupActor], remotePath), "lookupActor")
println("Started LookupSystem")
import system.dispatcher
system.scheduler.schedule(1.second, 1.second) {
if (Random.nextInt(100) % 2 == 0)
actor ! Add(Random.nextInt(100), Random.nextInt(100))
else
actor ! Subtract(Random.nextInt(100), Random.nextInt(100))
}
}
}
Other Akka source code examplesHere is a short list of links related to this Akka LookupApplication.scala source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.