is there a way to know when *really* an actor has stopped

117 views
Skip to first unread message

Kostas kougios

unread,
Oct 2, 2015, 10:58:54 AM10/2/15
to Akka User List
I create a named actor, stop it and recreate it with the same name. Because stop is async, I end up with exceptions like

  akka.actor.InvalidActorNameException: actor name [databaseServer] is not unique!
[info]   at akka.actor.dungeon.ChildrenContainer$NormalChildrenContainer.reserve(ChildrenContainer.scala:130)
[info]   at akka.actor.dungeon.Children$class.reserveChild(Children.scala:77)
[info]   at akka.actor.ActorCell.reserveChild(ActorCell.scala:373)
[info]   at akka.actor.dungeon.Children$class.makeChild(Children.scala:215)
[info]   at akka.actor.dungeon.Children$class.attachChild(Children.scala:42)
[info]   at akka.actor.ActorCell.attachChild(ActorCell.scala:373)
[info]   at akka.actor.ActorSystemImpl.actorOf(ActorSystem.scala:586)
[info]   at org.distributedrange.actors.StreamActor$$anonfun$2.apply(StreamActor.scala:122)

I get the same exception even if I set an AtomicBoolean to true at:

override def postStop() = {
stopped.set(true)
super.postStop()
}

and then

while (!stopped.get) {
Thread.sleep(1)
}

Is there a way to "block" and wait till the actor stops?
(don't worry about the block part, it is only for test cases)

Thanks

Ryan Tanner

unread,
Oct 2, 2015, 12:16:35 PM10/2/15
to Akka User List
Don't create the replacement actor until you've received a Terminated message for the original actor.

Kostas kougios

unread,
Oct 8, 2015, 5:46:13 AM10/8/15
to Akka User List
Thanks, I am doing that now and hopefully it works (the issue occurred very rarely, so I have to wait and see)

Patrik Nordwall

unread,
Oct 9, 2015, 1:08:26 AM10/9/15
to Akka User List
Note that this advice is correct but only when the parent actor receives the Terminated, i.e. it does not hold for top level actors where you can only watch from the "outside".
--
>>>>>>>>>> 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

Konstantinos Kougios

unread,
Oct 9, 2015, 6:59:28 AM10/9/15
to akka...@googlegroups.com
oh... in that case my code changes won't work. The watcher is not the parent of the actor.

Will it work if the watcher is child of the same parent of the Terminated actor?
/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 a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/u1TWqZYTKBE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

Patrik Nordwall

unread,
Oct 9, 2015, 7:17:52 AM10/9/15
to akka...@googlegroups.com
On Fri, Oct 9, 2015 at 12:59 PM, 'Konstantinos Kougios' via Akka User List <akka...@googlegroups.com> wrote:
oh... in that case my code changes won't work. The watcher is not the parent of the actor.

Will it work if the watcher is child of the same parent of the Terminated actor?

no, but what would a sibling do? it can't recreate the actor, it is only the parent that can create child actor with same name



--

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

Konstantinos Kougios

unread,
Oct 9, 2015, 7:23:21 AM10/9/15
to akka...@googlegroups.com
Well, I have this component based on 1 actor. It is the "flow" thing I was talking a few months ago, anyway it does take care of a process between different actors. One thing it does is to stop an other actor and wait till it is terminated. I need to make sure the other actor is really terminated because further down an actor with the same name is created - which randomly & rarely fails with "actor name [databaseServer] is not unique!"

Patrik Nordwall

unread,
Oct 9, 2015, 7:30:22 AM10/9/15
to akka...@googlegroups.com
it's probably easies to not reuse the name

Konstantinos Kougios

unread,
Oct 9, 2015, 11:59:17 AM10/9/15
to akka...@googlegroups.com
well, I am using actor paths to find the actors, which are unique per ActorSystem.

I.e. paths are

../databaseServer

../databaseServer/index:x1

../databaseServer/index:x2

I am using the akka cluster, so each "server" will have these paths.

Now when I do a "dropIndex" and drop index x1, actors ../databaseServer/index:x1 on each server must terminate. I would like to know precisely when that occurred, because a drop/recreate will have the issue of the same actor name.

Now I could, for tests, use a unique index name each time. But some tests need to drop/recreate the /databaseServer (and remember I refer to the indexes by ../databaseServer/index:x1)

Cheers

Michael Frank

unread,
Oct 9, 2015, 12:36:34 PM10/9/15
to akka...@googlegroups.com
instead of using actor paths to send directly to the index actor, why not send your message to the /databaseServer actor, which then forwards the message to the appropriate index actor?  the databaseServer actor would contain a Map[String,ActorRef] which maps index name to index actor (which are its children), and would register deathwatch on each child, so it would be notified when an index goes away and update its state.

-Michael

Konstantinos Kougios

unread,
Oct 9, 2015, 12:54:05 PM10/9/15
to akka...@googlegroups.com
A solution like this could work, but it is a lot more complicated (complexity added just to handle actor termination).

The databaseServer actor is not affected by the deaths of the indexes.

Btw, all my Terminated actors are local (same ActorSystem, same jvm) to the watcher, does that help?

Patrik Nordwall

unread,
Oct 9, 2015, 1:22:11 PM10/9/15
to akka...@googlegroups.com
Thanks for elaborating. I still don't understand why the databaseServer can't watch its index children and recreate them when it receives Terminated.

Regarding recreating the databaseServer itself (top level I guess) in tests I would not reuse the name.

Heiko Seeberger

unread,
Oct 9, 2015, 1:23:32 PM10/9/15
to akka...@googlegroups.com
A parent need not keep track of its children explicitly, there are `context.children` and `context.child(name)`.

Actor termination is not trivial, so some work needs to be done! Locality doesn’t help, termination works the same locally and remotely.

Maybe this is a use case for Cluster Sharding?

Heiko

--

Heiko Seeberger
Twitter: @hseeberger

Konstantinos Kougios

unread,
Oct 12, 2015, 4:51:55 PM10/12/15
to akka...@googlegroups.com
well, it could, but requires more work and it is more complex than having any actor .watch() for events.

Especially in my case that I need to watch for termination across the cluster, I would need a round trip to all parents (where as now I am just doing the round trip to the actors straight away)

Basically, my db "driver" issues a DropIndex msg to one of the db servers. That server then needs to monitor the whole process, making sure the drop index indeed occurred for all the cluster
Reply all
Reply to author
Forward
0 new messages