protected void configure() { Closeable executorCloser = new Closeable() { @Inject @Named(PROPERTY_USER_THREADS) ListeningExecutorService userExecutor; // ScheduledExecutor is defined in an optional module @Inject(optional = true) @Named(PROPERTY_SCHEDULER_THREADS) ScheduledExecutorService scheduledExecutor; public void close() throws IOException { assert userExecutor != null; userExecutor.shutdownNow(); // ScheduledExecutor is defined in an optional module if (scheduledExecutor != null) scheduledExecutor.shutdownNow(); } }; binder().requestInjection(executorCloser); Closer closer = new Closer(); closer.addToClose(executorCloser); bind(Closer.class).toInstance(closer); ExecutionList list = new ExecutionList(); bindPostInjectionInvoke(closer, list); bind(ExecutionList.class).toInstance(list); }
@Provides @Singleton ProvisioningManager provideProvisioningManager(Closer closer) { ProvisioningManager provisioningManager = new ProvisioningManager(); closer.addToClose(provisioningManager); return provisioningManager; }
@Override public boolean isOpen() { return closer.getState() == AVAILABLE; }