1
votes

I've actor MainActor which initializes and send messages for two other sub and expecting to get a result back. So MainActor has two child actors SubActorA and SubActorB.

Basically I want to build a model when data from sub actors has arrived I would be able to access it somewhere on a higher level (class which initialized MainActor)

For example I have 100 ms for both tasks. If SubActorA has returned data in 70 ms but SubActorB needs more time it would have 30 ms more and after all tasks will be abandoned, but I still interested in data and would like to have an access for it even if some of the sub tasks has time outed.

Questions:

  1. How do I limit whole execution for 100 ms so that in future I would be able to access data partially from each actor?

  2. How do I access data from actor on highest level? I cannot all the time push data to higher level again and again by extending from UntypedActor and sending messages to higher level. I have tried to create a WrapperHandler which would initialize MainActorbut unfortunately getting exception You have to use one of the 'actorOf' factory methods to create a new actor. Of course I can do that using actorOf method and invoke .tell() method to send a message to the actor which starts all the job. But how do I get a response back if I am not extending UntypedActor and not overriding onRecieve() method anymore?

Thanks for any help!

1

1 Answers

3
votes

Everything in Akka is based on message-passing. If you want to get data from an actor, you ask for it (send a message) and the actor will (maybe) reply (send another message).

Fortunately, Akka provides a helper called ask that lets you send messages from outside an actor and receive the reply as a Future. You send a message via the ask helper to your MainActor from outside your actor hierarchy (or wherever you instantiated MainActor), the MainActor will reply with your data.

http://doc.akka.io/docs/akka/2.3.9/java/untyped-actors.html#Ask__Send-And-Receive-Future