I think you can do that with Akka’s Coordinated Shutdown
https://doc.akka.io/docs/akka/current/actors.html#coordinated-shutdown

Register your task to one of the phases, instead of using jvm shutdown
hook. Coordinated Shutdown will be triggered by jvm exit.

/Patrik
tis 13 feb. 2018 kl. 12:52 skrev Kilic Ali-Firat <kilic.alifi...@gmail.com>:

> Hi,
>
> I'm working on a part of my Akka application which must gracefully
> shutdown when a shutdown hook has been detected.
>
> The use case of my question is in case of deployment while the application
> is making some tasks. In this specific case, we do want to delay the
> deployment until my actors have not finished their tasks.
>
> My application is composed by a ClusterGroup with a limited number of
> routees (worker actors). To make a graceful shutdown, I like idea in
> following article:
> http://letitcrash.com/post/30165507578/shutdown-patterns-in-akka-2
>
> Basically what I want to do is :
>
>    1. Create a Reaper as in the article, collected dead souls
>    2. A shutdown hook has been detected, send a PoisonPill to each actors
>    in my actor system (I have all the elements for that)
>    3. When all worker actors has been killed with seeing PoisonPill
>    message, shutdown the actor system + the application (using System.exit or
>    something else)
>
> My main problem is that I need a mechanism of Akka or Scala to wait (or to
> timeout) the termination of my worker actors.
>
> I'm using following code to detect that my application has been shutdown
> from an external signal :
>
>
>  scala.sys.addShutdownHook {
>     // let actors finished their work, blocking call ?
>
>     }
>
>
> For reader of this question, I'm using Akka 2.5.7 and Scala 2.11.11.
>
> Can I have advices for such use case ? I don't think that I'm only one to
> make such things so I'm listening all ideas :)
>
> --
> >>>>>>>>>> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to akka-user@googlegroups.com.
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
>>>>>>>>>>      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+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to