akka.actor.InvalidActorNameException: actor name [xxx] is not unique!

1,406 views
Skip to first unread message

Kane Lai

unread,
Feb 11, 2015, 10:58:58 AM2/11/15
to akka...@googlegroups.com
Hi,

I'm trying to manually restart the akka hierarchy because I'm implementing something like hot-reload config mechanism.
I send a Kill to a top level actor and set the supervisor strategy for ActorKilledException to Restart. Everything works fine so far.
Then during restart, in the top level actor constructor I recreate the child actors like this. Then the InvalidActorNameException is seen. May I know what's the usual practice to handle this? How could I recreate and name the reborn child actors?
Thanks.

val worker =
context.actorOf(
TcpServerWorker.props(
self,
config.operationSetConfig.tcpListenHost.get,
config.operationSetConfig.tcpListenPort.get),
"tcpServer")

Kane

Ryan Tanner

unread,
Feb 11, 2015, 9:36:39 PM2/11/15
to akka...@googlegroups.com
From the documentation on stopping actors:

Since stopping an actor is asynchronous, you cannot immediately reuse the name of the child you just stopped; this will result in an InvalidActorNameException. Instead, watch the terminating actor and create its replacement in response to the Terminated message which will eventually arrive.

Patrik Nordwall

unread,
Feb 13, 2015, 5:24:04 AM2/13/15
to akka...@googlegroups.com
It should be possible to restart without having the name collision of the child. Do you override the preRestart method? By default preRestart stops all children and waits (non-blocking) until they are terminated. This is explained in What Restarting Means

Ryan's observation is important for another scenario, e.g. this will not work:
val child = context.actorOf(Props[Child], "child")
context.stop(child)
context.actorOf(Props[Child], "child") // boom

Cheers,
Patrik




--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> 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 akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--

Patrik Nordwall
Typesafe Reactive apps on the JVM
Twitter: @patriknw

 Scala Days

Reply all
Reply to author
Forward
0 new messages