The life cycle of an application
An application's life cycle has two states: running and stopped. These are times when the state of the application changes. At times, we need to perform some operations right before or after a state change has occurred or is about to occur.
Play applications use a Netty server. For this, a class with the same name is used. It is defined as follows:
class NettyServer(appProvider: ApplicationProvider, port: Option[Int], sslPort: Option[Int] = None, address: String = "0.0.0.0", val mode: Mode.Mode = Mode.Prod) extends Server with ServerWithStop { … }
This class is responsible for binding or bootstrapping the application to the server.
The ApplicationProvider
trait is defined as follows:
trait ApplicationProvider { def path: File def get: Try[Application] def handleWebCommand(requestHeader: play.api.mvc.RequestHeader): Option[Result] = None }
An implementation of ApplicationProvider
must create and initialize an application. Currently, there are three different...