3

我的环境是eclipse、play、akka、scala。尝试创建远程主 akka 演员时出现错误。

我不确定为什么会收到此错误:

[InvalidActorNameException:演员名称你好不是唯一的!]

当用户提交表单时,calculate调用:

options => {
     this.calculate(options.numWorkers.toInt, options.numElements.toInt,          options.numMessages.toInt) 
     //Redirect(routes.Application.)
     Ok(html.form(this.optionsForm))
}

这是我创建演员的代码

val master = RemoteSystem.system.actorOf(Props[Master], "hello")

我也只创建了这个演员的一个实例,并尝试了许多其他名称,例如masterMastermaster1983274612987346198356

Master定义为:

class Master extends Actor {

    var pi: Double = _
    var nrOfResults: Int = _
    var start: Long = _

    def receive = {
        case calculate(numWorkers, numElements, numMessages) =>{
            for (i <- 0 until numWorkers) {
                val worker = RemoteSystem.system.actorOf(Props[Worker], "Worker")
                for(j <- 0 until numMessages) 
                {
                    worker ! Work(0, numElements)      
                }
            }
        }
        case PiResult(start, numTerms, acc) => println("Pi Result: " + acc)
    }

    override def preStart() {
        start = System.currentTimeMillis
    }

    override def postStop() {
        println(
"\n\tCalculation time: \t%s millis".format(System.currentTimeMillis - start))
    }
}

演员系统是:

object RemoteSystem {
    val system = ActorSystem(
"RemoteCreation", ConfigFactory.load.getConfig("remotecreation"))
}

其中remotecreation定义为:

remotecreation{
    include "common"

    akka {
        actor{
            deployment{
                /Worker{
                    remote="akka://Pi@10.0.100.254:2552"
                }
            }
        }
    remote.netty.port = 2554
    }
}
4

1 回答 1

4

在以下代码中,您似乎正在创建许多具有相同名称“Worker”的工人:

for (i <- 0 until numWorkers) {
      val worker = RemoteSystem.system.actorOf(Props[Worker], "Worker")
      for(j <- 0 until numMessages) 
      {
         worker ! Work(0, numElements)      
      }
}

您需要移动演员创建代码(请参阅此文档):

class Master extends Actor {
    val worker = RemoteSystem.system.actorOf(Props[Worker], "Worker")
    ...
}
于 2012-07-27T21:06:27.943 回答