The following link describes how to handle module initialization and destruction in Guice using a Service interface with a start() and stop() method:
https://github.com/google/guice/wiki/ModulesShouldBeFastAndSideEffectFree
The documentation explains that the creation of the service looks like this in client code:
public static void main(String[] args) throws Exception {
Injector injector = Guice.createInjector(
new DatabaseModule(),
new WebserverModule(),
...
);
Service databaseConnectionPool = injector.getInstance(
Key.get(Service.class, DatabaseService.class));
databaseConnectionPool.start();
addShutdownHook(databaseConnectionPool);
Service webserver = injector.getInstance(
Key.get(Service.class, WebserverService.class));
webserver.start();
addShutdownHook(webserver);
}
But does not list any sample implementation of a Concrete Service class. Can anyone provide me with one? At least a sample implementation of what would start() and stop() contain.