0

I have a method getAggOutput() that returns a HashMap, in Actor A.

def getAggOutput: HashMap[X, List[Y]] = {
    println("***** Inside getAggOutput, rMap is: " + rMap)
    return rMap
 }

Also, in Actor A, the method is called that under the case object GETOUTPUT:

case GETOUTPUT =>
   println("***** Inside GETOUTPUT")
   getAggOutput

In Actor B, I am doing the following:

 implicit val timeout = Timeout(5 seconds)
 val reducerInput = sender ? GETOUTPUT
 val result = Await.result(reducerInput, timeout.duration)
 println("****** RESULT is: " + result)

The print statements show that the value for rMap is correct, however, I am getting the following error:

java.util.concurrent.TimeoutException: Futures timed out after [5 seconds]

And result is not assigned the value of the HashMap.

How do I make this work? Or, is there a better way entirely? I just need to get rMap into Actor B

UPDATE:

I figured out this part. In the case GETOUTPUT, I need:

sender ! getAggOutput.  

The println shows that the HashMap in the result variable is correct.

Now, I am trying to loop over the HashMap:

 for( (key,value) <- result)
     {
       redOut += (key -> value)
     }

And I am getting the following error:

type mismatch;
[error]  found   : (Any, Any)
[error]  required: (X, U)
[error]            redOut += (key -> value)

UPDATE:

I also tried:

for( (key,value) <- result)
     {
       redOut += (key.asInstanceOf[X] -> value.asInstanceOf[U])
     }

However, I received the following error:

value withFilter is not a member of Any
[error]          for( (key,value) <- result)
user1317750
  • 51
  • 2
  • 8
  • I see you already solved it, but to add to that: avoid sending mutable state in messages between actors it is not safe and never use Await.result inside of an actor - read up on ask and pipeTo in the Akka docs to see alternatives. – johanandren Jun 08 '17 at 13:29

1 Answers1

0

There was no need to do this, I just looped over the Hashmap in Actor A and sent each (key, value) pair to Actor B

user1317750
  • 51
  • 2
  • 8