My application needs to fetch some resource bundles on Application Startup. I want the application to wait for these resources to be loaded and not serve any requests until this loading has finished. So i basically want good old java blocking behavior. Therefore i tried to place some blocking behavior into the Unit method beforeStart
in the Global
singleton object of my application.
object Global extends GlobalSettings {
override def onStart(app: Application) {
Logger.info("begin: Global.onStart")
val resourcesFetched = ResourceService.fetchResourceBundles()
import scala.concurrent.duration._
Await.result(resourcesFetched, 30.second)
Logger.info("end: Global.onStart")
}
}
This approach currently works for me, but it looks awkward to me. Is there some other hook i should use? I haven't found something appropriate within the documentation.
If that is what you want Global.onStart is exactly what you should do, I'm pretty sure there isn't a better place where you can affect the start up process and make the entire webapp wait for it to complete.