Package org.apache.druid.guice
Class LifecycleModule
java.lang.Object
org.apache.druid.guice.LifecycleModule
- All Implemented Interfaces:
com.google.inject.Module
A Module to add lifecycle management to the injector.
DruidGuiceExtensions must also be included.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconfigure(com.google.inject.Binder binder) getLifecycle(com.google.inject.Injector injector) static voidRegisters a class to instantiate eagerly.static voidregister(com.google.inject.Binder binder, Class<?> clazz, Class<? extends Annotation> annotation) Registers a class/annotation combination to instantiate eagerly.static voidregisterKey(com.google.inject.Binder binder, com.google.inject.Key<?> key) Registers a key to instantiate eagerly.
-
Constructor Details
-
LifecycleModule
public LifecycleModule()
-
-
Method Details
-
register
Registers a class to instantiate eagerly. Classes mentioned here will be pulled out of the injector with an injector.getInstance() call when the lifecycle is created. Eagerly loaded classes will *not* be automatically added to the Lifecycle unless they are bound to the proper scope. That is, they are generally eagerly loaded because the loading operation will produce some beneficial side-effect even if nothing actually directly depends on the instance. This mechanism exists to allow theLifecycleto be the primary entry point from the injector, not to auto-register things with theLifecycle. It is also possible to just bind things eagerly with Guice, but that is almost never the correct option. Guice eager bindings are pre-instantiated before the object graph is materialized and injected, meaning that objects are not actually instantiated in dependency order. Registering with the LifecyceModule, on the other hand, will instantiate the objects after the normal object graph has already been instantiated, meaning that objects will be created in dependency order and this will only actually instantiate something that wasn't actually depended upon.- Parameters:
clazz- the class to instantiate
-
register
public static void register(com.google.inject.Binder binder, Class<?> clazz, Class<? extends Annotation> annotation) Registers a class/annotation combination to instantiate eagerly. Classes mentioned here will be pulled out of the injector with an injector.getInstance() call when the lifecycle is created. Eagerly loaded classes will *not* be automatically added to the Lifecycle unless they are bound to the proper scope. That is, they are generally eagerly loaded because the loading operation will produce some beneficial side-effect even if nothing actually directly depends on the instance. This mechanism exists to allow theLifecycleto be the primary entry point from the injector, not to auto-register things with theLifecycle. It is also possible to just bind things eagerly with Guice, but that is almost never the correct option. Guice eager bindings are pre-instantiated before the object graph is materialized and injected, meaning that objects are not actually instantiated in dependency order. Registering with the LifecyceModule, on the other hand, will instantiate the objects after the normal object graph has already been instantiated, meaning that objects will be created in dependency order and this will only actually instantiate something that wasn't actually dependend upon.- Parameters:
clazz- the class to instantiateannotation- The annotation class to register with Guice
-
registerKey
public static void registerKey(com.google.inject.Binder binder, com.google.inject.Key<?> key) Registers a key to instantiate eagerly.Keys mentioned here will be pulled out of the injector with an injector.getInstance() call when the lifecycle is created. Eagerly loaded classes will *not* be automatically added to the Lifecycle unless they are bound to the proper scope. That is, they are generally eagerly loaded because the loading operation will produce some beneficial side-effect even if nothing actually directly depends on the instance. This mechanism exists to allow theLifecycleto be the primary entry point from the injector, not to auto-register things with theLifecycle. It is also possible to just bind things eagerly with Guice, but that is almost never the correct option. Guice eager bindings are pre-instantiated before the object graph is materialized and injected, meaning that objects are not actually instantiated in dependency order. Registering with the LifecyceModule, on the other hand, will instantiate the objects after the normal object graph has already been instantiated, meaning that objects will be created in dependency order and this will only actually instantiate something that wasn't actually dependend upon.- Parameters:
key- The key to use in finding the DruidNode instance
-
configure
public void configure(com.google.inject.Binder binder) - Specified by:
configurein interfacecom.google.inject.Module
-
getLifecycle
-