Package org.apache.druid.guice
Class LifecycleModule
- java.lang.Object
-
- org.apache.druid.guice.LifecycleModule
-
- All Implemented Interfaces:
com.google.inject.Module
public class LifecycleModule extends Object implements com.google.inject.Module
A Module to add lifecycle management to the injector.DruidGuiceExtensions
must also be included.
-
-
Constructor Summary
Constructors Constructor Description LifecycleModule()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure(com.google.inject.Binder binder)
Lifecycle
getLifecycle(com.google.inject.Injector injector)
static void
register(com.google.inject.Binder binder, Class<?> clazz)
Registers a class to instantiate eagerly.static void
register(com.google.inject.Binder binder, Class<?> clazz, Class<? extends Annotation> annotation)
Registers a class/annotation combination to instantiate eagerly.static void
registerKey(com.google.inject.Binder binder, com.google.inject.Key<?> key)
Registers a key to instantiate eagerly.
-
-
-
Method Detail
-
register
public static void register(com.google.inject.Binder binder, Class<?> clazz)
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 theLifecycle
to 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 theLifecycle
to 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.Key
s 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 theLifecycle
to 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:
configure
in interfacecom.google.inject.Module
-
getLifecycle
@Provides public Lifecycle getLifecycle(com.google.inject.Injector injector)
-
-