The Artima Developer Community
Sponsored Link

Akka Concurrency Forum
Section 6.5 - gracefulStop

9 replies on 1 page. Most recent reply: Oct 22, 2012 11:06 PM 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 9 replies on 1 page
Eric Pederson

Posts: 12
Nickname: 71552
Registered: Apr, 2010

Section 6.5 - gracefulStop Posted: Oct 22, 2012 7:11 AM
Reply to this message Reply
Advertisement
You may want to mention an alternative while testing to gracefulStop:

awaitCond(actor.isTerminated)


Derek Wyatt

Posts: 69
Nickname: dwyatt
Registered: Oct, 2012

Re: Section 6.5 - gracefulStop Posted: Oct 22, 2012 9:44 AM
Reply to this message Reply
Thanks Eric. I agree it's an alternative, but I'm not sure it's terribly ideal. gracefulStop has a purpose that does not equate to waiting on isTerminated == true.

I totally want to encourage comments, so if this is the ideal way for you to do it, please continue. However, if you can use the 'suggest' link in the eBook, that would be better for me, as it helps me keep things organized better.

Eric Pederson

Posts: 12
Nickname: 71552
Registered: Apr, 2010

Re: Section 6.5 - gracefulStop Posted: Oct 22, 2012 10:12 AM
Reply to this message Reply
Will do. I didn't realize that was there.

Eric Pederson

Posts: 12
Nickname: 71552
Registered: Apr, 2010

Re: Section 6.5 - gracefulStop Posted: Oct 22, 2012 10:25 AM
Reply to this message Reply
Could you elaborate? I have been using awaitCond(actor.isTerminated) in my tests when I need to reuse actor names.

Derek Wyatt

Posts: 69
Nickname: dwyatt
Registered: Oct, 2012

Re: Section 6.5 - gracefulStop Posted: Oct 22, 2012 2:09 PM
Reply to this message Reply
There's no guarantee that isTerminated and the 'name reuse' will coincide. It may be serendipitous that it's working for you (which is great), but there's no guarantee that it will; they're simply not connected in the code flow (at this time).

The only way I've found to truly do this in a reliable way is to isolate the ActorSystem on a per-test basis, which lets me reuse the names as much as I'd like.

Eric Pederson

Posts: 12
Nickname: 71552
Registered: Apr, 2010

Re: Section 6.5 - gracefulStop Posted: Oct 22, 2012 2:42 PM
Reply to this message Reply
Yep - just looked at the code. isTerminated is true before the parent is sent the Terminated message, and the check for duplicate names happens at the parent. I'll have to use the ActorSystem-per test trick from the book (nice trick!).

Eric Pederson

Posts: 12
Nickname: 71552
Registered: Apr, 2010

Re: Section 6.5 - gracefulStop Posted: Oct 22, 2012 3:00 PM
Reply to this message Reply
Interesting that the first thing that gracefulStop does is check actor.isTerminated :)

Eric Pederson

Posts: 12
Nickname: 71552
Registered: Apr, 2010

Re: Section 6.5 - gracefulStop Posted: Oct 22, 2012 4:54 PM
Reply to this message Reply
I could emulate gracefulStop and watch the actor that I am stopping and then, if I get a Terminated assume that the parent has already processed the stop and I can go ahead and reuse the name. But it's still a race condition.

Another thing to do is put the actor creation in a retry loop... Ugh.

Derek Wyatt

Posts: 69
Nickname: dwyatt
Registered: Oct, 2012

Re: Section 6.5 - gracefulStop Posted: Oct 22, 2012 11:00 PM
Reply to this message Reply
"gracefulStop" is intended to gracefully stop things (duh :D), and while you are doing the same-ish thing that it's doing, that doesn't mean you're doing a graceful stop. But, either way, neither of them technically do what you want them to do.

I hit this a long time ago and it annoyed me a lot, but the reuse of a name is merely a nicety for testing, not for production code. And it's this reason why I use ActorSystem isolation instead, in these rare cases where an Actor's name is vital to the structure of the application.

This fits with, and works with, what the toolkit provides. Going with the flow is going to pay off... not only now, but as things change.

Derek Wyatt

Posts: 69
Nickname: dwyatt
Registered: Oct, 2012

Re: Section 6.5 - gracefulStop Posted: Oct 22, 2012 11:06 PM
Reply to this message Reply
Ah, but if I read far enough back, I see you get all that :)

Cheers,
D

Flat View: This topic has 9 replies on 1 page
Topic: Which version of Scala, Akka are  used in the book ? Previous Topic   Next Topic Topic: Section 6.6

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use