Netflix/governator — pull request #111 by elandau (2014-04-11 05:30:15+00:00)
Title: Adding concept of an application runner

This pull requests adds the concept of an application runner that will handle the runtime lifecycle of an entire application (i.e starting LifecycleManager, waiting for the application to exit, closing LifecycleManager) as part of the LifecycleInjector bootstrapping and allow for much simpler integration with the container in which Governator is used (i.e Standalone, Jetty, Tomcat, …). This method is an alternative to having to get the instance of LifecycleManager and calling start() and close() outside of governator. A specific runner implementation is implemented as a BootstrapModule which must provide a binding to LifecycleRunner.

Example standalone application,
```java
public class Application {
@Inject
public Application(@Main List args) {
}

public static void main(String[] args) {
LifecycleInjector.builder()
.withAdditionalBootstrapModules(
StandaloneRunnerModule.builder()
.withTerminateEvent(new SelfDestructingTerminationEvent(10, TimeUnit.SECONDS))
.withArgs(args)
.withMainClass(Application.class)
.build())
.build(); // Calling build will trigger creating the runner
}
}
```

I also prototyped a simple Jetty based runner and would like to add it as a sub project but governor has not been set up for sub projects yet. Any suggesting for how to proceed would be greatly appreciated.

A Jetty based hello world app would look like this
```java
@Path("/")
public class HelloWorldWebApp {

public static void main(String[] args) {
LifecycleInjector.builder()
.withModules(new JerseyServletModule() {
@Override
protected void configureServlets() {
bind(HelloWorldWebApp.class);
bind(GuiceContainer.class).asEagerSingleton();
serve("/*").with(GuiceContainer.class);
}
})
.withAdditionalBootstrapModules(new JettyRunnerModule())
.build();
}

@GET
public String hello() {
return "hello";
}
}
```