From: John Stanford <jxstanf...@gmail.com>
Date: Tue, 20 Mar 2012 11:31:30 -0700
Local: Tues, Mar 20 2012 2:31 pm
Subject: Re: [akka-user] sending messages to an actor inside a future
Hi Roland and Derek,
Thanks for the ideas. I did simplify the case quite a bit for the example, and do need to replace the otherActor if it is recreated because it's parent restarted. This is probably a good case for an FSM and as Viktor was kind enough to point out in another conversation, Stash. Here we go! Thanks, On Mar 20, 2012, at 10:20 AM, Roland Kuhn wrote: > Hi John,
> On Mar 20, 2012, at 17:19 , John Stanford wrote: >> Hi, >> Just want to make sure I understand this properly. Let's say I have this actor: >> class MyActor extends Actor { >> val otherActor = context.parent ? MyOtherActorRequest mapTo manifest[ActorRef] >> def receive = { >> case m: Message => otherActor map (_ forward m) >> case _ => () >> And let's say there are two messages in MyActor's mailbox. Will the otherActor future need to be completed before the second message it taken from the mailbox for processing? Is there a more appropriate way to deal with this other actor to avoid the map operation on every incoming message? Clearly I could Await it, but that would violate the goal of non-blocking. > As you are getting that ActorRef from the parent, why not simply pass it in as constructor argument? If it is a cyclic dependency thing, I’d model this actor as a state machine which starts out “queueing” and will turn into “forwarding” upon reception of that ActorRef (thereby draining the queue). This is the only way to retain the order of messages; if that is not needed, your solution should work just fine (although I would use foreach instead of map). > Regards, > Roland Kuhn > -- You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||