The Artima Developer Community
Sponsored Link

Akka Concurrency Forum
Ch 10.5, .withRouter and naming

4 replies on 1 page. Most recent reply: Mar 1, 2013 4:28 AM by Derek Wyatt

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Dan Luu

Posts: 27
Nickname: amitra
Registered: Feb, 2013

Ch 10.5, .withRouter and naming Posted: Feb 28, 2013 12:11 PM
Reply to this message Reply
Advertisement
When I name the LeadFlightAttendant as in the text ("/Plane/LeadFlightAttendant"), I get a runtime error indicating that slashes aren't allowed in the name, but it works fine and the router config is resolved correctly if I just name it "LeadFlightAttendant".

It seems to me that my fix makes sense, but it's possible that I'm just using a different version of akka or scala, which is causing an issue? I'm currently using scala 2.10.0 with akka 2.1.1.


Dan Luu

Posts: 27
Nickname: amitra
Registered: Feb, 2013

Re: Ch 10.5, .withRouter and naming Posted: Feb 28, 2013 12:17 PM
Reply to this message Reply
A related question is, what the heck does this change do?

So, now we've created a LeadFlightAttendant actor that uses a random router.

But, in LeadFlightAttendant.scala, we still have the following code:


def randomAttendant(): ActorRef = {context.children.take(
scala.util.Random.nextInt(numberOfAttendants)+ 1).last}

def receive = {
case GetFlightAttendant => sender ! Attendant(randomAttendant())
case m => randomAttendant() forward m
}


So, we also need to make a change that's analogous to the PassengerSupervisor, to get this to really do what's intended, right? Or am I missing some magic that will cause this to work regardless?

Derek Wyatt

Posts: 64
Nickname: dwyatt
Registered: Oct, 2012

Re: Ch 10.5, .withRouter and naming Posted: Mar 1, 2013 3:43 AM
Reply to this message Reply
You can't name actors with slashes in them. The path to the actor is made up of slashes that gets built up that way based on the hierarchy. i.e. if you create an actor called "Plane" and then a child of that is created called "LeadFlightAttendent" then the path to the child is "/Plane/LeadFlightAttendant". And, of course, the Plane is actually at "/user/Plane" because the User Guardian is the ultimate root of all user-level actors in the actor system.

Derek Wyatt

Posts: 64
Nickname: dwyatt
Registered: Oct, 2012

Re: Ch 10.5, .withRouter and naming Posted: Mar 1, 2013 4:26 AM
Reply to this message Reply
The router removes the LeadFlightAttendant as a bottleneck. Now, the LeadFlightAttendant isn't a bottleneck to begin with so the example isn't great...

But here's the idea. If you create the LeadFlightAttendant with the router, then when you ask it for an attendant, you'll be asking a routed LeadFlightAttendant. Let's say I do the following:

leadAttendant ? GetFlightAttendant onComplete println
leadAttendant ? GetFlightAttendant onComplete println
leadAttendant ? GetFlightAttendant onComplete println
leadAttendant ? GetFlightAttendant onComplete println

Then I may get the following output from those printlns:

Success(Attendant(Actor[akka://LeadFlightAttendantSpec/user/Plane/L eadFlightAttendant/$d/Heiko]))
Success(Attendant(Actor[akka://LeadFlightAttendan tSpec/user/Plane/LeadFlightAttendant/$a/Martin]))
Success(Attendant(Actor[akka:/ /LeadFlightAttendantSpec/user/Plane/LeadFlightAttendant/$d/Heiko]))
Success(Atte ndant(Actor[akka://LeadFlightAttendantSpec/user/Plane/LeadFlightAttendant/$d/Hei ko]))

Note the names. The requests for GetFlightAttendant go to different routed LeadFlightAttendants, and the actors that come back are children of those different routed LeadFlightAttendants.

Derek Wyatt

Posts: 64
Nickname: dwyatt
Registered: Oct, 2012

Re: Ch 10.5, .withRouter and naming Posted: Mar 1, 2013 4:28 AM
Reply to this message Reply
Ah, and I see what you're getting at with the "/Plane/LeadFlightAttendant" thing... that's totally my fault. Thanks for the bug report. You need to change the creation of the leadAttendant to:

val leadAttendant =
context.actorOf(Props(newFlightAttendant).withRouter(
FromConfig()),
"LeadFlightAttendant")

Flat View: This topic has 4 replies on 1 page
Topic: Chapter 8 :  Runtime error when using a concrete IsolatedResumeSupervisor Previous Topic   Next Topic Topic: Ch 10.4, passenger list typesetting


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us