我的环境是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")
我也只创建了这个演员的一个实例,并尝试了许多其他名称,例如master
、Master
和master1983274612987346198356
。
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
}
}