I'm developing my app with Akka and Play2.
When I run the play2 app with ~run
the first time and I make a GET my custom Actor system is created in the Controller and it starts a cluster on 2558 port.
If a change anything in my code and make another GET play recompiles and start over as it suppose to but the 2558 port is taken and I've got error: Failed to bind to /127.0.0.1:2558
.
I don't know how to handle my own actors systems shutdown to work well with play2.
I've tried to do it in the GlobalSettings
object in onStop
method but with no luck.
Use play.api.libs.concurrent.Akka.system
to get an actor system. You can customise this actor system however you want in application.conf
. Play automatically starts it up and shuts it down for you.
If for some reason you really don't want to use this (but really, I can't think of any reason why you would ever not use it), then you need to wait for the actor system to shutdown in the GlobalSettings.onStop
method, using ActorSystem.awaitTermination
. Calling shutdown
is non blocking, so when Play starts it back up, it's likely that the ActorSystem
won't have fully shut down and released the port yet.
Also, don't create the actor system in a controller. Either create it in Global
, or implement the play.api.Plugin
interface and create one there (the latter is preferred for anything that has a lifecycle).