One decent approach is to use Guava's Service & ServiceManager <https://code.google.com/p/guava-libraries/wiki/ServiceExplained>, then bind your services using a multibinder and @Provides a ServiceManager constructed with the result of that multibinder. Then you can just start/stop the ServiceManager, which will start/stop each service.
sam On Thu, Oct 2, 2014 at 1:53 PM, Kevin Burton <[email protected]> wrote: > I have a bunch of services that need to be started and stopped. ActiveMQ > , Cassandra, Jetty, etc... > > They use files, start ports, etc. > > I imagine the best strategy to just have a leif Node service just start > its dependencies in its start() method.. then stop them. > > So the could would look something like the following... > > but it would be nice if the start/stop methods were auto-wrapped ... > > This way on shutdown all threads and resources can be properly released. > > This is also helpful in testing so that if you have an impl that creates > threads they can be released. > > public class Main { > > public static void main( String... args ) { > > MyService service = injector.getInstance( MyService.class ) > > } > > } > > public class MyService { > > @Inject > MyService( WebserverService webserverService ) { > ... > } > > public void start() { > webserverService.start(); > } > > public void stop() { > webserverService.stop(); > } > > } > > > public class Webserver { > > @Inject > MyService( CassandraService cassandraService ) { > ... > } > > public void start() { > cassandraService.start(); > } > > public void stop() { > cassandraService.stop(); > } > > } > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/google-guice. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-guice/f5e11810-1aa3-4a4c-882a-ddc84d258e57%40googlegroups.com > <https://groups.google.com/d/msgid/google-guice/f5e11810-1aa3-4a4c-882a-ddc84d258e57%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-guice. To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/CAJEBNUdjyiTBC9B6RKVzip_CJgMOSqnc7eVDBTT6cHZ2AVyjxw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
