Hi Ash,

http://doc.akka.io/docs/akka/2.4.1/additional/faq.html#sender___getSender___disappears_when_I_use_Future_in_my_Actor__why_

On Tue, Jan 12, 2016 at 7:10 PM, ash.ta <[email protected]> wrote:

> hi hakkers,
>
> i have two actors: the first one patterns.ask() a message to the second
> one which returns a response:
>
> a snippet osender:
>
> ...
>     public PartialFunction<Object, BoxedUnit> receive() {
>         return ReceiveBuilder
>                 .match( Boolean.class, msg -> {
>                     ActorRef receiver = context().system()
>                                                  .actorOf( Props.create( 
> ReceiveActor.class ), ReceiveActor.class
>                                                          .getSimpleName() );
>                     Future<Object> future = Patterns.ask( receiver, "Hello 
> world", new Timeout( Duration
>                             .create( 5, "seconds" ) ) );
>                     Patterns.pipe( future, context().dispatcher() ).to( 
> self() );
>                 } )
>                 .match( String.class, msg-> log(msg) )
>                 .build();
>     }
>     *...*
>
>
> receiver:
>
> ...
>     public PartialFunction<Object, BoxedUnit> receive() {
>
>         return ReceiveBuilder.matchAny( msg -> {
>             sender().tell( ((String)msg).toUpperCase(), self() );
>         } ).build();
>     }
> ...
>
>
> all is good, a message is sent and response arrives as expected.
>
> now, i try to change a receiver so that the message handling is done in a
> separate thread:
>
> ...
> public PartialFunction<Object, BoxedUnit> receive() {
>     return ReceiveBuilder.matchAny( msg -> {
>         Future<String> done= Futures.future( (Callable<String>) () -> 
> ((String)msg).toUpperCase(), context().dispatcher() ) ;
>         done.onSuccess( new OnSuccess<String>() {
>             @Override
>             public void onSuccess( String result ) throws Throwable {
>                 sender().tell( result, self() );
>             }
>         }, context().dispatcher() );
>     } ).build();
> }
> ...
>
>
> in this case i get the following error:
>
> [akka://main/deadLetters] Message [java.lang.String] from
> Actor[akka://main/user/ReceiveActor#603147641] to
> Actor[akka://main/deadLetters] was not delivered.
>
> it seems that sender() within the future is not recognizable as my sender
> actor anymore.
>
> what do i miss and what is the solution?
>
> thanks!
>
> --
> >>>>>>>>>> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Cheers,
√

-- 
>>>>>>>>>>      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 [email protected].
To post to this group, send email to [email protected].
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