There's a number of possibilities: if the processing is stateless you could
use the 'ask' and 'pipe' patterns and 'map' (
http://doc.akka.io/docs/akka/current/java/futures.html#Use_with_Actors ).

Another approach might be to wrap the messages to and from the child actors
in an 'envelope' that also contains some kind of unique 'correlation id',
and in MainActor keep a Map from correlation id to original sender.


Arnout

On Tue, Apr 25, 2017 at 10:33 AM, Vishwa Bhat <git.vishwab...@gmail.com>
wrote:

> Nice, That's one solution but what if I have to do some processing on
> 'MainActor' when I get response from child and then I have to send to
> 'MyApp'?
>
> Regards,
> Vishwa
>
> On Tuesday, April 25, 2017 at 1:38:09 PM UTC+5:30, Arnout Engelen wrote:
>>
>> Hi Vishwa,
>>
>> You correctly noticed that, when handling the Integer message that was
>> sent to the 'MainActor' by your child actor, 'sender()' will refer to that
>> child actor.
>>
>> If you want the response to go to the 'original' sender ('MyApp'), one
>> solution might be to use 'sender()' as the second parameter to 'route':
>> this will tell the child to send its response directly to 'MyApp',
>> effectively 'forwarding' the message.
>>
>>
>> Kind regards,
>>
>> Arnout
>>
>> On Tue, Apr 25, 2017 at 8:57 AM, Vishwa Bhat <git.vis...@gmail.com>
>> wrote:
>>
>>> I have the following issue in Akka-Java.
>>>
>>> I have one Parent Actor `MainActor.class` and this parent has 5 child
>>> routes. Following is the hierarchy:
>>>
>>> *My App => Main Actor => [Child Route-1,Child-Route-2,..]*
>>>
>>> Simple Use case is String input is parsed to Integer as output:
>>>
>>> *MyApp ===ask[string input]===> Main Actor ==route==> Child(parses to
>>> Integer) === integer result===> Main Actor ===result==> MyApp*
>>>
>>> Here is the Main Actor snippet:
>>>
>>>
>>>  class MainActor extends UntypedActor{
>>>
>>>        Router router;
>>>        {
>>>          // ...routes are configured here
>>>        }
>>>
>>>        public void onReceive(Object message){
>>>          if(message instanceof String){
>>>              router.route(message,self()); // route it to child
>>>          }else if(message instanceof Integer){
>>>             // received from child, 'tell' this result to actual
>>> sender/parent i.e, MyApp
>>>             sender().tell(message,self());
>>>          }else unhandled(message);
>>>         }
>>>  }
>>>
>>> And Child Actor does nothing but String parsing to Integer and takes the
>>> result and sends it back to it's sender by `sender().tell(result,getConte
>>> xt().parent())`
>>>
>>> *Issue*
>>>
>>> MainActor is sending the Parsed integer result sent by child back to
>>> child itself instead of `MyApp`. I also tried replacing `*sender()*` to
>>> `*getContext().parent()*` in `MainActor` but still it did not work.
>>>
>>> --
>>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>>> >>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/c
>>> urrent/additional/faq.html
>>> >>>>>>>>>> Search the archives: https://groups.google.com/grou
>>> p/akka-user
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "Akka User List" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to akka-user+...@googlegroups.com.
>>> To post to this group, send email to akka...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/akka-user.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Arnout Engelen
>> *Senior Software Engineer*
>> E: arnout....@lightbend.com
>> T: https://twitter.com/raboofje
>>
>>
>> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/
> current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to akka-user+unsubscr...@googlegroups.com.
> To post to this group, send email to akka-user@googlegroups.com.
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Arnout Engelen
*Senior Software Engineer*
E: arnout.enge...@lightbend.com
T: https://twitter.com/raboofje

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to