public final class LifecycleInjector extends DelegatingInjector
LifecycleInjector injector = new Governator().run();
// ...
injector.shutdown();
Blocking on the injector terminating
LifecycleInjector injector = new Governator().run(;
// ...
injector.awaitTermination();
Triggering shutdown from a DI'd class
@Singleton
public class SomeShutdownService {
@Inject
SomeShutdownService(LifecycleManager lifecycleManager) {
this.lifecycleManager = lifecycleManager;
}
void someMethodInvokedForShutdown() {
this.lifecycleManager.shutdown();
}
}
}
Triggering an external event from shutdown without blocking
LifecycleInjector injector = new Governator().run(;
injector.addListener(new LifecycleListener() {
public void onShutdown() {
// Do your shutdown handling here
}
});
}
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(com.netflix.governator.spi.LifecycleListener listener)
Register a single shutdown listener for async notification of the LifecycleManager
terminating.
|
void |
awaitTermination()
Block until LifecycleManager terminates
|
static LifecycleInjector |
createFailedInjector(LifecycleManager manager) |
void |
shutdown()
Shutdown LifecycleManager on this Injector which will invoke all registered
LifecycleListeners and unblock awaitTermination. |
static LifecycleInjector |
wrapInjector(com.google.inject.Injector injector,
LifecycleManager manager) |
createChildInjector, createChildInjector, findBindingsByType, getAllBindings, getBinding, getBinding, getBindings, getExistingBinding, getInstance, getInstance, getMembersInjector, getMembersInjector, getParent, getProvider, getProvider, getScopeBindings, getTypeConverterBindings, injectMemberspublic static LifecycleInjector createFailedInjector(LifecycleManager manager)
public static LifecycleInjector wrapInjector(com.google.inject.Injector injector, LifecycleManager manager)
public void awaitTermination()
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic void shutdown()
LifecycleListeners and unblock awaitTermination.public void addListener(com.netflix.governator.spi.LifecycleListener listener)
listener -