supervisers and supervisee state

32 views
Skip to first unread message

Jason Mason

unread,
May 17, 2012, 1:58:51 PM5/17/12
to akka...@googlegroups.com
hi

given the following scenario:

A receives a message about a new node/service/server to monitor. A spawns actor B1 passing in the URL to monitor, using an UntypedActorFactory. it does so for each server it gets told to monitor. actors B1, B2 etc monitors the servers they were assigned with some form of RPC and reports their monitoring results back to A. 

now, B2 dies and gets restarted by A. 

1. does it use the same UntypedActorFactory originally used to create B2?
2. how does it magically know what state was assigned to B2? 

or do i have to somehow manually keep track of this state in A? (currently there's no need). 

thanks!

√iktor Ҡlang

unread,
May 17, 2012, 3:35:01 PM5/17/12
to akka...@googlegroups.com
On Thu, May 17, 2012 at 7:58 PM, Jason Mason <jason....@gmail.com> wrote:
hi

given the following scenario:

A receives a message about a new node/service/server to monitor. A spawns actor B1 passing in the URL to monitor, using an UntypedActorFactory. it does so for each server it gets told to monitor. actors B1, B2 etc monitors the servers they were assigned with some form of RPC and reports their monitoring results back to A. 

now, B2 dies and gets restarted by A. 

1. does it use the same UntypedActorFactory originally used to create B2?

yes
 
2. how does it magically know what state was assigned to B2? 


there is no magic so I do not understand the question, care to elaborate?

Cheers,
 
or do i have to somehow manually keep track of this state in A? (currently there's no need). 

thanks!

--
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/-/OgLJB1cJcoEJ.
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

Jason Mason

unread,
May 21, 2012, 4:45:00 PM5/21/12
to akka...@googlegroups.com
hi viktor

here's a gist that hopefully illustrates my question better:


if it's still unclear i'd be happy to elaborate further. 

thanks

Roland Kuhn

unread,
May 21, 2012, 4:54:31 PM5/21/12
to akka...@googlegroups.com
I guess that you mean “will it be created for the same «message» object”, and the answer to that is “yes”. The UntypedActorFactory is a local class which captures the value of the message parameter in its (hidden, auto-generated) constructor. Nothing magic, all bog-standard Java semantics.

BTW: I would recommend not to “handle” any failures like you do. Returning null only makes matters worse (i.e. obfuscates the real source of the error, which would otherwise be logged after Viktor heroically fixed that just a few hours ago ;-) ).

Regards,

Roland

--
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/-/rMvtSG1p2DAJ.

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
Typesafe – The software stack for applications that scale.
twitter: @rolandkuhn


√iktor Ҡlang

unread,
May 21, 2012, 4:54:51 PM5/21/12
to akka...@googlegroups.com
On Mon, May 21, 2012 at 10:45 PM, Jason Mason <jason....@gmail.com> wrote:
hi viktor

here's a gist that hopefully illustrates my question better:



No need to catch the exception, just rethrow.
Also instead of "Akka.system().scheduler().schedule(Duration.Zero(), Duration.parse("1 seconds"), actor, JMXWorker.Message.POLL);"

Use getContext().setReceiveTimeout(…)
 
Also, avoid creating top-level Actors unless it makes sense, since it is both a blocking operation and it creates a very flat supervision tree, so instead of Akka.system.actorOf use getContext().actorOf to create it as a child so you can supervise it. Also, you can get access to the current actors ActorSystem by calling getContext().getSystem so avoid global state if possible.

I don't know if that answers your question though.

Cheers,

if it's still unclear i'd be happy to elaborate further. 

thanks

--
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/-/rMvtSG1p2DAJ.

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.

Jason Mason

unread,
May 21, 2012, 7:24:03 PM5/21/12
to akka...@googlegroups.com

really appreciate all the gratuitous input guys, worth gold! 

i knocked together a quick app to prove this to myself and indeed works as you said: 

https://gist.github.com/2765156

in order to restart the child with the correct state... does the parent actor context store a reference to the instance of the props (and UntypedActorFactory instance) used to create each child actor? 

also, sounds like good advice about not "handling" the error in the UntypedActorFactory (https://gist.github.com/2764527) but it looks like the abstract create() method doesn't support checked exceptions, unless i'm having an obtuse moment :) how do you handle Actors that throws checked exceptions from their constructors?

Reply all
Reply to author
Forward
0 new messages