Hi Derek,
On Fri, Dec 20, 2013 at 5:05 PM, Derek <[email protected]> wrote: > Hi, > > I'd like clarification regarding something Roland mentioned in the > Coursera Reactive Programming class (which my co-workers and I have really > found useful - nice job Roland!). In one of the lectures he was discussing > the guarantee that Akka makes regarding the order in which messages are > received -- specifically that messages between sender-receiver actor pairs > will not be delivered out of order. > > We'd like to know how the guarantee applies when the sender is not > explicitly an Actor but some other object that has obtained an ActorRef via > actorSelection? If I look up the ref once and cache it and then send > multiple messages using that same ref instance, does the same guarantee > apply as between actor pairs? > Yes, if you send from the same thread. > > What if I don't cache the ref but select it each time this object wants to > send a message to that same actor ref? > You mean sending the messages with the actor selection? system.actorSelection("/user/a/b") ! "msg-1" system.actorSelection("/user/a/b") ! "msg-2" system.actorSelection("/user/a/b") ! "msg-3" The order for those messages will also be preserved. If you mix actor reference and actor selection the order is undefined. selToB ! "msg-1" refToB ! "msg-2" // might arrive before or after msg-1 > > Guessing that even though my object that is sending messages is not an > actor, under the covers and in order for the message send to work > correctly, an implicit sender Actor is created and then the message order > guarantee applies between that sender-receiver pair? So, as long as I > cache the ActorRef and re-use it the guarantee will hold but if I perform > an actorSelection each time it may not? > To give you a better understanding I can explain how actor selection is implemented. ActorSelection consist of an anchor ActorRef and path elements. The anchor for actorSelection("/user/a/b") is the root guardian actor. For actorSelection("akka.tcp://my-sys@anotherhost:2552/user/a/b") it is the root guardian at the remote actor system "my-sys@anotherhost:2552". When you invoke tell on the ActorSelection a special ActorSelectionMessage is created and sent to the anchor. It wraps the original message and includes the path elements of the ActorSelection. When the anchor actor receives this message it traverses the actor tree corresponding to the path elements. Note that this is done by the anchor actor, and since it is an actor it processes one ActorSelectionMessage at a time. Finally it delivers the message with an ordinary tell of the ActorRef of the destination, i.e. it is enqueued in the mailbox of destination actor. Paths that contain wildcards and remote deployed actors are treated in a slightly different way. This is how it works in upcoming 2.3 version. In 2.2 the traversal of the actor path is done with message passing between each actor in the path. Cheers, Patrik > > Thanks and Merry Christmas, > -Derek > > -- > >>>>>>>>>> Read the docs: http://akka.io/docs/ > >>>>>>>>>> Check the FAQ: http://akka.io/faq/ > >>>>>>>>>> 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 http://groups.google.com/group/akka-user. > For more options, visit https://groups.google.com/groups/opt_out. > -- Patrik Nordwall Typesafe <http://typesafe.com/> - Reactive apps on the JVM Twitter: @patriknw -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: http://akka.io/faq/ >>>>>>>>>> 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 http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/groups/opt_out.
