首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Akka(三)Start with first Project - Second Part

2013-01-17 
Akka(3)Start with first Project - Second PartAkka(3)Start with first Project - Second PartCreating

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


热点排行