【问题标题】:Parallel program running in scala在scala中运行的并行程序
【发布时间】:2014-10-29 19:37:27
【问题描述】:

我能够创建演员并在本地运行它们。但现在我希望演员在网络上连接的计算机上运行代码。假设我想创建演员来查找数字的阶乘。

object FactorialAll extends Actor{
   def receive = {
     case (n:Int)=>
         for(i<-1 to n){
          var factorActor = context.actorOf(Prop[FactorActor],"factorActor")
          factorActor ! Factorial(i)
         }
     case Result(n:Int,fact:BigInt)=>
        println("factorial of " + n + " is "+fact)
   }
}

然后我们向这个 Actor 发送一些 int。

如何创建和运行 FactorActor 实例以在网络上运行。

【问题讨论】:

    标签: java scala parallel-processing actor reactive-programming


    【解决方案1】:

    要仅向远程参与者发送消息,您需要 Akka Remoting:http://doc.akka.io/docs/akka/current/scala/remoting.html

    然后,您可以获取远程actor并发送如下消息:

    val selection =
      context.actorSelection("akka.tcp://actorSystemName@host:1234/user/actorName")
    
    selection ! "fooBar"
    

    【讨论】:

      猜你喜欢
      • 2013-03-18
      • 2016-08-17
      • 2014-07-12
      • 2017-05-04
      • 1970-01-01
      • 2014-12-06
      • 2015-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多