Comment #103 on issue 62 by [email protected]: Lifecycle support
http://code.google.com/p/google-guice/issues/detail?id=62

PROPOSAL 102.

Add an extension that uses Guava's Service interface, and that makes it easy to bind services and start them.

Perhaps a basic service registration DSL:
  class MyAppServiceModule extends ServiceModule {
    public void configureServices() {
      bindService(JettyService.class);
      service(JettyService.class).dependsOn(ConnectionPoolService.class);
    }
  }

Plus a mechanism to start and stop services. This could track user-specified service dependencies.

public static void main(String... args) {
  Stopwatch stopwatch = new Stopwatch();
  Injector injector = ...
  logger.info("Injector creation took " + stopwatch.elapsed());
  stopwatch.reset();

ServiceManager serviceManager = injector.getInstance(ServiceManager.class);
  serviceManager.registerServiceFailureHandler(new ServiceFailureHandler() {
    public void serviceFailed(Service service, Throwable failure) {
logger.log(WARNING, "Service " + service + " failed; shutting down", failure);
      serviceManager.shutdown();
    }
  });
serviceManager.registerShutdownOnExitHook(); // gracefully shut down on CTRL-C
  serviceManager.startAllAndWait();
  logger.info("Service startup took " + stopwatch.elapsed());
  logger.info("Ready");
}

Ideally ServiceManager has a rich API that lets you do all the natural things you want to do with services. Stuff like starting them up, shutting them down, listening for state changes, printing statistics like startup time, and interrogating the dependency graph. It could even do its own logging (in a verbose mode?) to keep the common case concise.

--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice-dev?hl=en.

Reply via email to