Akka总是超时等待未来

时间:2013-09-13 21:46:06

标签: scala akka

我对Akka很新,并试图弄清楚如何从我的代码中获得结果,我有以下内容:

object MyClass extends Controller {

def createCluster(id: String, uuid: String, loc: String, size: String, quantity: Int, name: String) = { implicit request =>
Async{
Akka.future {
.....
  val system = ActorSystem("System")

  val master = system.actorOf(Props[Master], name = "master")
  val launch = Launch(s, d, request.user, quantity, clusterName)

  //val future = master ? launch
  implicit val timeout = Timeout(5 minutes)

  val future = Patterns.ask(master, launch, timeout) //master ? launch
  val result = Await.result(future.mapTo[ServerContainer], timeout.duration)
}
}

我的主要演员看起来像:

class Master() extends Actor {

def receive = {
case Launch(server, details, user, quantity, clusterName) => {
  d = details
  s = Some(server)
  u = Some(user)
  q = Some(quantity)
  cname = Some(clusterName)
  hostnameActor ! Host(BIServer.NONE, Server.PDI, Database.NONE, server.uuid.getOrElse(""), None)
}
case Host(bi,etl,db,uuid,name2) => {
  instance = name2
  h = Some(Host(bi,etl,db,uuid,name2))
  templateActor ! TemplateOpts(s.get, d.get, instance.get)
}

case TemplateContainer(client,temp,id, server, _, _, _,_, _) => {
  nodeActor ! TemplateContainer(client,temp,id, server, d.get, h, q, u, cname)}

case NodeContainer(server, details, meta, dns, host, key) => { n = Some(NodeContainer(server,details,meta,dns,host,q))
  etlServerActor ! n.get
}

case ServerContainer(server,details) => {
  sender ! ServerContainer(server, details)
}
}

所有actor都已成功执行,但ServerContainer永远不会返回给发件人,即使该行是根据调试器执行的,并且请求总是在5分钟后超时。

任何人都可以提出任何想法吗?

1 个答案:

答案 0 :(得分:1)

您在sender范围内引用的case ServerContainer实际上是ServerContainer邮件的发件人,而不是Launch的原始发件人

您应该将 发件人的某些引用视为变量,或者通过传递消息来传递