{8.0.0-new, 8.1.2-deprecated} Lifecycle Methods

To review, the {@link oaj.microservice.Microservice} class contains the following lifecycle methods:

- {@link oaj.microservice.Microservice}
  - {@link oaj.microservice.Microservice#start() start()}
  - {@link oaj.microservice.Microservice#startConsole() startConsole()}
  - {@link oaj.microservice.Microservice#join() join()}
  - {@link oaj.microservice.Microservice#stop() stop()}
  - {@link oaj.microservice.Microservice#stopConsole() stopConsole()}
  - {@link oaj.microservice.Microservice#exit() exit()}
  - {@link oaj.microservice.Microservice#kill() kill()}

The {@link oaj.microservice.jetty.JettyMicroservice} class which extends from {@link oaj.microservice.Microservice} provides the following additional lifecycle methods:

- {@link oaj.microservice.jetty.JettyMicroservice}
  - {@link oaj.microservice.jetty.JettyMicroservice#createServer() createServer()}
  - {@link oaj.microservice.jetty.JettyMicroservice#startServer() startServer()}
  - {@link oaj.microservice.jetty.JettyMicroservice#destroyServer() destroyServer()}

The additional lifecycle methods are typically not called directly, but are exposed to allow subclasses to provide customized behavior for these events. For this reason, these methods are left as non-final so that they can be overridden.

A typical implementation of an app with lifecycle methods might look like the following:

public class App { private static final JettyMicroservice MICROSERVICE; public static void main(String[] args) { MICROSERVICE = JettyMicroservice .create() // Create builder. .args(args) // Pass in args. .servlets(RootResource.class) // A Juneau RestServlet class. .build() // Create microservice. .start() // Start microservice. .startConsole() // Start console. .join() // Join thread. ; } public static void restart() { MICROSERVICE.stop().start(); } public static void exit() { MICROSERVICE.exit(); } }

Similar to {@link oaj.microservice.Microservice#getInstance()}, the {@link oaj.microservice.jetty.JettyMicroservice#getInstance()} also allows easy access to the microservice:

public class App { public static void main(String[] args) { JettyMicroservice .create() // Create builder. .args(args) // Pass in args. .servlets(RootResource.class) // A Juneau RestServlet class. .build() // Create microservice. .start() // Start microservice. .startConsole() // Start console. .join() // Join thread. ; } public static void restart() { JettyMicroservice.getInstance().stop().start(); } public static void exit() { JettyMicroservice.getInstance().exit(); } }