magicaltrout
magicaltrout

Reputation: 504

Akka always timeout waiting for future

I'm rather new to Akka and trying to figure out how to get a result from my code, I have the following:

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)
}
}

And my main Actor looks like:

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)
}
}

All the actors are executed successfully but the ServerContainer is never returned to the sender even though that line is executed according to the debugger, and the request always timesout after 5 minutes.

Can anyone lend any ideas as to why?

Upvotes: 0

Views: 483

Answers (1)

pagoda_5b
pagoda_5b

Reputation: 7373

The sender you refer to in the scope of case ServerContainer is actually the sender of the ServerContainer message and not the original sender of Launch

You should hold to some reference of that sender as a variable or even better by passing it around with the messages exchange

Upvotes: 1

Related Questions