Looking up actors in 2.0

76 views
Skip to first unread message

andy

unread,
Apr 26, 2012, 7:17:50 PM4/26/12
to akka...@googlegroups.com

Hello,

When looking up an actor

context.actorFor( "myactor" )

an ActorRef will be returned for the running actor or an ActorRef that forwards messages to the dead letter actor will be returned. The path for both of these will be:

akka://MySystem/myparent/myactor

which means that I can't ever tell if I actually have an actor running. I can look up children from a parent using context.children.find(..... but as the docs mention

val badLookup = context.children find (_.path.name == "kid")
// should better be expressed as:
val goodLookup = context.actorFor("kid")

this is a slow way to look up actors especially if a parent has thousands/hundreds of thousands of children.

My path forward has been to keep a HashMap of the actor name and the actor ref and use context.watch( child ) to remove actors from the map when they shut themselves down.

Am I correct that there really isn't a way to look up a running actor in 2.0, and actually know if it is the actor you wanted?

Thanks,
Andy

√iktor Ҡlang

unread,
Apr 26, 2012, 7:25:22 PM4/26/12
to akka...@googlegroups.com
Hey Andy,

On Fri, Apr 27, 2012 at 1:17 AM, andy <andrew....@gmail.com> wrote:

Hello,

When looking up an actor

context.actorFor( "myactor" )

an ActorRef will be returned for the running actor or an ActorRef that forwards messages to the dead letter actor will be returned. The path for both of these will be:

akka://MySystem/myparent/myactor

which means that I can't ever tell if I actually have an actor running.

Which makes total sense because in an asynchronous environment something might die the same nanosecond you look at it, or a nanosecond later.

use watch() and unwatch() or in rare cases "isTerminated" to observe death.
 
I can look up children from a parent using context.children.find(..... but as the docs mention

val badLookup = context.children find (_.path.name == "kid")
// should better be expressed as:
val goodLookup = context.actorFor("kid")

this is a slow way to look up actors especially if a parent has thousands/hundreds of thousands of children.

See above
 

My path forward has been to keep a HashMap of the actor name and the actor ref and use context.watch( child ) to remove actors from the map when they shut themselves down.

See above.
 

Am I correct that there really isn't a way to look up a running actor in 2.0, and actually know if it is the actor you wanted?

See above.

Cheers,
 

Thanks,
Andy

--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/IgiXQuy_y3cJ.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: @viktorklang

andy

unread,
Apr 26, 2012, 7:28:07 PM4/26/12
to akka...@googlegroups.com
Killer thanks. Just making sure. I'm battling the upgrade beast and I almost have it licked.

-Andy
Hey Andy,


Thanks,
Andy
To unsubscribe from this group, send email to akka-user+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

√iktor Ҡlang

unread,
Apr 26, 2012, 7:32:44 PM4/26/12
to akka...@googlegroups.com
On Fri, Apr 27, 2012 at 1:28 AM, andy <andrew....@gmail.com> wrote:
Killer thanks. Just making sure. I'm battling the upgrade beast and I almost have it licked.

You're welcome,

happy hAkking

Cheers,
 
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/9gNLzvJBLb8J.

To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

Roland Kuhn

unread,
Apr 27, 2012, 3:12:27 AM4/27/12
to akka...@googlegroups.com, akka...@googlegroups.com
Hi Andy,

let me add that context.actorFor already does the book-keeping including DeathWatch, so just use 

context.actorFor("blah").isTerminated

That is the most efficient way. 


Regards,

Roland Kuhn
Typesafe — The software stack for applications that scale
twitter: @rolandkuhn
--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/IgiXQuy_y3cJ.
To post to this group, send email to akka...@googlegroups.com.

Roland Kuhn

unread,
Apr 27, 2012, 3:16:07 AM4/27/12
to akka...@googlegroups.com, akka...@googlegroups.com
just to be clear: the book-keeping is done only for direct children. 
Reply all
Reply to author
Forward
0 new messages