`
sillycat
  • 浏览: 2551745 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

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


分享到:
评论

相关推荐

    akka-actor-2.11-2.5.19-API文档-中文版.zip

    赠送jar包:akka-actor_2.11-2.5.19.jar; 赠送原API文档:akka-actor_2.11-2.5.19-javadoc.jar; 赠送源代码:akka-actor_2.11-2.5.19-sources.jar; 赠送Maven依赖信息文件:akka-actor_2.11-2.5.19.pom; 包含...

    akka-stream_2.11-2.5.21-API文档-中文版.zip

    赠送jar包:akka-stream_2.11-2.5.21.jar; 赠送原API文档:akka-stream_2.11-2.5.21-javadoc.jar; 赠送源代码:akka-stream_2.11-2.5.21-sources.jar; 赠送Maven依赖信息文件:akka-stream_2.11-2.5.21.pom; ...

    akka-actor_2.11-2.5.21-API文档-中文版.zip

    赠送jar包:akka-actor_2.11-2.5.21.jar; 赠送原API文档:akka-actor_2.11-2.5.21-javadoc.jar; 赠送源代码:akka-actor_2.11-2.5.21-sources.jar; 赠送Maven依赖信息文件:akka-actor_2.11-2.5.21.pom; 包含...

    akka-stream_2.11-2.5.21-API文档-中英对照版.zip

    赠送jar包:akka-stream_2.11-2.5.21.jar; 赠送原API文档:akka-stream_2.11-2.5.21-javadoc.jar; 赠送源代码:akka-stream_2.11-2.5.21-sources.jar; 赠送Maven依赖信息文件:akka-stream_2.11-2.5.21.pom; ...

    akka-actor_2.11-2.4.20-API文档-中英对照版.zip

    赠送jar包:akka-actor_2.11-2.4.20.jar; 赠送原API文档:akka-actor_2.11-2.4.20-javadoc.jar; 赠送源代码:akka-actor_2.11-2.4.20-sources.jar; 赠送Maven依赖信息文件:akka-actor_2.11-2.4.20.pom; 包含...

    akka-protobuf_2.11-2.4.20-API文档-中英对照版.zip

    赠送jar包:akka-protobuf_2.11-2.4.20.jar; 赠送原API文档:akka-protobuf_2.11-2.4.20-javadoc.jar; 赠送源代码:akka-protobuf_2.11-2.4.20-sources.jar; 赠送Maven依赖信息文件:akka-protobuf_2.11-2.4.20....

    akka-actor_2.11-2.5.19-API文档-中英对照版.zip

    赠送jar包:akka-actor_2.11-2.5.19.jar; 赠送原API文档:akka-actor_2.11-2.5.19-javadoc.jar; 赠送源代码:akka-actor_2.11-2.5.19-sources.jar; 赠送Maven依赖信息文件:akka-actor_2.11-2.5.19.pom; 包含...

    akka--------------介绍

    akka接触信息

    akka-persistence-sql-async, 一个用于akka持久性的日志和快照存储.zip

    akka-persistence-sql-async, 一个用于akka持久性的日志和快照存储 akka-persistence-sql-async 的日志和快照存储插件( akka持久化插件。 Akka-persistence-sql-async执行由 scalikejdbc异步查询,它提供非阻塞api来...

    akka-actor_2.11-2.4.20-API文档-中文版.zip

    赠送jar包:akka-actor_2.11-2.4.20.jar; 赠送原API文档:akka-actor_2.11-2.4.20-javadoc.jar; 赠送源代码:akka-actor_2.11-2.4.20-sources.jar; 赠送Maven依赖信息文件:akka-actor_2.11-2.4.20.pom; 包含...

    akka-protobuf_2.11-2.4.20-API文档-中文版.zip

    赠送jar包:akka-protobuf_2.11-2.4.20.jar; 赠送原API文档:akka-protobuf_2.11-2.4.20-javadoc.jar; 赠送源代码:akka-protobuf_2.11-2.4.20-sources.jar; 赠送Maven依赖信息文件:akka-protobuf_2.11-2.4.20....

    akka-stream_2.11-2.4.20-API文档-中文版.zip

    赠送jar包:akka-stream_2.11-2.4.20.jar; 赠送原API文档:akka-stream_2.11-2.4.20-javadoc.jar; 赠送源代码:akka-stream_2.11-2.4.20-sources.jar; 赠送Maven依赖信息文件:akka-stream_2.11-2.4.20.pom; ...

    akka-kryo-serialization, 基于Kryo的Akka序列化.zip

    akka-kryo-serialization, 基于Kryo的Akka序列化 akka-kryo-serialization-- Scala 和Akka基于kryo的序列化程序这个库为 Scala 和Akka提供定制的基于kryo的序列化程序。 它可以用于更高效的akka远程处理。它还可以...

    akka-stream_2.11-2.4.20-API文档-中英对照版.zip

    赠送jar包:akka-stream_2.11-2.4.20.jar; 赠送原API文档:akka-stream_2.11-2.4.20-javadoc.jar; 赠送源代码:akka-stream_2.11-2.4.20-sources.jar; 赠送Maven依赖信息文件:akka-stream_2.11-2.4.20.pom; ...

    akka-actor_2.11-2.5.21-API文档-中英对照版.zip

    赠送jar包:akka-actor_2.11-2.5.21.jar; 赠送原API文档:akka-actor_2.11-2.5.21-javadoc.jar; 赠送源代码:akka-actor_2.11-2.5.21-sources.jar; 赠送Maven依赖信息文件:akka-actor_2.11-2.5.21.pom; 包含...

    akka-actor_2.11 jar包

    akka-actor_2.11 jar包

    akka-remote_2.10-2.2.3-shaded-protobuf.zip

    p-unit.zip,一个基于junit和groovy ssh dsl的groovy库,用于验证puppet模块的结果;一个基于junit和sshoogr(groovy ssh dsl)的groovy库,用于验证配置脚本(puppet、chef、ansible等)的结果。

    akka-actor-1.0-RC2.jar.zip

    《Akka Actor库详解——基于akka-actor-1.0-RC2.jar.zip的剖析》 Akka是一个由Lightbend公司维护的开源框架,主要用于构建高度并发、分布式和反应式的应用程序。在Java和Scala平台上,Akka因其强大的性能和易用性而...

    akka-streams-kafka-examples-源码.rar

    在"akka-streams-kafka-examples-源码.rar"压缩包中,我们可以深入理解Akka Streams如何与Kafka进行交互,以及如何利用它们的优势来处理大数据流。下面我们将详细探讨其中的关键知识点。 1. **Akka Streams基础** ...

    基于akka-http、akka-cluster、akka-stream 构建的报表工具

    基于scala 、akka实现了一个简单的报表工具。该项目是个玩具项目,用于个人学习scala和akka。使用scala语言开发,基于akka-http, akka-stream,akka-cluster等新...流控 Back-Pressure, 避免OutOfMemory(akka-stream).

Global site tag (gtag.js) - Google Analytics