Akka(3)Start with first Project - Second Part

Akka(3)Start with first Project - Second Part
Creating the result Listener
class Listener extends Actor { // Everything is Actor
def receive = {
case PiApproximation(pi, duration) =>
println("\n\tPi approximation: \t\t%s\n\tCalculation time: \t%s".format(pi, duration))
//print out the result
context.system.shutdown()
//shutdown the system
}
}

Bootstrap the calculation
We will extend the App trait in Scala, which means that we will be able to run this as an application directly from the command line.

object Pi extends App {
calculate(nrOfWorkers = 4, nrOfElements = 10000, nrOfMessages = 10000)

…snip...
def calculate(nrOfWorkers: Int, nrOfElements: Int, nrOfMessages: Int) {
// Create an Akka system
val system = ActorSystem("PiSystem")

// create the result listener, which will print the result and
// shutdown the system
val listener = system.actorOf(Props[Listener], name = "listener")

// create the master
val master = system.actorOf(Props(new Master(
nrOfWorkers, nrOfMessages, nrOfElements, listener)),
name = "master")

// start the calculation by send the Calculate message to master actor
master ! Calculate
}
}

We also have a test case there, I can run that via Eclipse JUnit and Scala Test.

No, I can not understand that. I will go on with the documents to learn more.


References:
http://doc.akka.io/docs/akka/2.1.0/
http://doc.akka.io/docs/akka/2.1.0/general/index.html

https://github.com/typesafehub
http://typesafe.com/resources/tutorials/getting-started-with-akka-scala.html#getting-started-with-akka-scala

http://alvinalexander.com/scala/java.lang.nosuchmethoderror-scala.predef.augmentstring-error

http://stackoverflow.com/questions/11203268/what-is-a-sealed-trait
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值