Class DropwizardAwareModule<C extends io.dropwizard.core.Configuration>
- Type Parameters:
C- configuration type
- All Implemented Interfaces:
com.google.inject.Module,BootstrapAwareModule<C>,ConfigurationAwareModule<C>,ConfigurationTreeAwareModule,EnvironmentAwareModule,OptionsAwareModule
- Direct Known Subclasses:
GuiceBootstrapModule,UniqueDropwizardAwareModule
- Since:
- 06.06.2015
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> TannotatedConfiguration(Annotation annotation) Search for exactly one annotated configuration value.protected <T> TannotatedConfiguration(Class<? extends Annotation> qualifierType) Search for exactly one configuration value with qualifier annotation (without attributes).protected Stringprotected io.dropwizard.core.setup.Bootstrap<C>protected Cprotected <T,K extends T>
Kconfiguration(Class<T> type) May be used to access unique sub configuration object.protected <T> Tconfiguration(String yamlPath) May be used to access current configuration value by exact path.protected <T> List<? extends T>configurations(Class<T> type) IMPORTANT: method semantic is different fromconfiguration(Class), which use direct class declaration match, whereas this method searches by all assignable types.protected ConfigurationTreeRaw configuration introspection info.protected io.dropwizard.core.setup.Environmentprotected Optionsoptions()voidsetBootstrap(io.dropwizard.core.setup.Bootstrap<C> bootstrap) Method will be called just before injector initialization.voidsetConfiguration(C configuration) Method will be called just before injector initialization.voidsetConfigurationTree(ConfigurationTree configurationTree) Mathod will be called just before injector initialization.voidsetEnvironment(io.dropwizard.core.setup.Environment environment) Method will be called just before injector initialization.voidsetOptions(Options options) Method will be called just before injector initialization.protected <T> Optional<T>sharedState(Class<T> key) Access shared value.<T> TsharedState(Class<T> key, Supplier<T> defaultValue) Alternative shared value initialization for cases when first accessed bundle should init state value and all other just use it.protected <T> TsharedStateOrFail(Class<T> key, String message, Object... args) Used to access shared state value and immediately fail if value not yet set (most likely, due to incorrect configuration order).<V> voidshareState(Class<V> key, V value) Share global state to be used in other bundles (during configuration).protected <V> voidwhenSharedStateReady(Class<V> key, Consumer<V> action) Reactive shared value access: if value already available action called immediately, otherwise action would be called when value set (note that value could be set only once).Methods inherited from class com.google.inject.AbstractModule
addError, addError, addError, bind, bind, bind, bindConstant, binder, bindInterceptor, bindListener, bindListener, bindScope, configure, configure, convertToTypes, currentStage, getMembersInjector, getMembersInjector, getProvider, getProvider, install, requestInjection, requestInjection, requestStaticInjection, requireBinding, requireBinding
-
Constructor Details
-
DropwizardAwareModule
public DropwizardAwareModule()
-
-
Method Details
-
setConfiguration
Description copied from interface:ConfigurationAwareModuleMethod will be called just before injector initialization.- Specified by:
setConfigurationin interfaceConfigurationAwareModule<C extends io.dropwizard.core.Configuration>- Parameters:
configuration- configuration object
-
setBootstrap
Description copied from interface:BootstrapAwareModuleMethod will be called just before injector initialization.- Specified by:
setBootstrapin interfaceBootstrapAwareModule<C extends io.dropwizard.core.Configuration>- Parameters:
bootstrap- bootstrap object
-
setEnvironment
public void setEnvironment(io.dropwizard.core.setup.Environment environment) Description copied from interface:EnvironmentAwareModuleMethod will be called just before injector initialization.- Specified by:
setEnvironmentin interfaceEnvironmentAwareModule- Parameters:
environment- environment object
-
setOptions
Description copied from interface:OptionsAwareModuleMethod will be called just before injector initialization.- Specified by:
setOptionsin interfaceOptionsAwareModule- Parameters:
options- options object
-
setConfigurationTree
Description copied from interface:ConfigurationTreeAwareModuleMathod will be called just before injector initialization.- Specified by:
setConfigurationTreein interfaceConfigurationTreeAwareModule- Parameters:
configurationTree- introspected configuration object
-
bootstrap
- Returns:
- application bootstrap object
-
configuration
- Returns:
- application configuration
-
configuration
May be used to access current configuration value by exact path. This is helpful for modules universality: suppose bundle X requires configuration object XConf, which is configured somewhere inside application configuration. We can require configuration path in module constructor and use it to access required configuration object:new X("sub.config.path").- Type Parameters:
T- value type- Parameters:
yamlPath- target value yaml path- Returns:
- configuration value by path or null if value is null or path not exists
- See Also:
-
configuration
May be used to access unique sub configuration object. This is helpful for modules universality: suppose module X requires configuration object XConf and we are sure that only one declaration of XConf would be used in target configuration class, then we can simply request it:configuration(XConf.class) == <instance of XConf or null>.Note that uniqueness is checked by declaration class:
are unique declarations (declaration of the same type never appears in configuration on any level).class Config extends Configuration { Sub sub; SubExt ext; // SubExt extends Sub }configuration(Sub.class) == subandconfiguration(SubExt.class) == ext.Example of accessing server config from dropwizard configuration:
configuration(ServerFactory.class) == <DefaultServerFactory> (or SimpleServerFactory)(see dropwizardConfigurationclass).- Type Parameters:
T- declaration typeK- required value type (may be the same or extending type)- Parameters:
type- target configuration declaration type- Returns:
- unique configuration value or null if value is null or no declaration found
- See Also:
-
configurations
IMPORTANT: method semantic is different fromconfiguration(Class), which use direct class declaration match, whereas this method searches by all assignable types.class Config extends Configuration { Sub sub; SubExt ext; // SubExt extends Sub }configurations(Sub.class) == [sub, ext], butconfigurations(SubExt.class) == [ext].Useful when multiple sub configuration objects could be used and all of them are required in some universal module.
Note: only custom types may be used (sub configuration objects), not Integer, Boolean, List, etc.
- Type Parameters:
T- value type- Parameters:
type- target configuration type- Returns:
- list of configuration values with required type or empty list
- See Also:
-
annotatedConfiguration
Search for exactly one annotated configuration value. It is not possible to provide the exact annotation instance, but you can create a class implementing annotation and use it for search. For example, guiceNamedannotation hasNames.named(String): it is important that real annotation instance and "pseudo" annotation object would be equal.For annotations without attributes use annotation type:
annotatedConfiguration(Class).For multiple values use
configurationTree().annotatedValues().- Type Parameters:
T- value type- Parameters:
annotation- annotation instance (equal object) to search for an annotated config path- Returns:
- qualified configuration value or null
- Throws:
IllegalStateException- if multiple values found
-
annotatedConfiguration
Search for exactly one configuration value with qualifier annotation (without attributes). For cases when annotation with attributes used - useannotatedConfiguration(java.lang.annotation.Annotation)(current method would search only by annotation type, ignoring any (possible) attributes).For multiple values use
configurationTree().annotatedValues().- Type Parameters:
T- value type- Parameters:
qualifierType- qualifier annotation type- Returns:
- qualified configuration value or null
- Throws:
IllegalStateException- if multiple values found
-
configurationTree
Raw configuration introspection info. Could be used for more sophisticated configuration searches then provided in shortcut methods.Note that configuration is analyzed using jackson serialization api, so not all configured properties could be visible (when property getter is not exists or field not annotated).
Returned object contains all resolved configuration paths. Any path element could be traversed like a tree. See find* and value* methods as an examples of how stored paths could be traversed.
- Returns:
- detailed configuration object
- See Also:
-
environment
protected io.dropwizard.core.setup.Environment environment()- Returns:
- application environment
-
appPackage
- Returns:
- application class package (most likely root package for entire application)
-
options
- Returns:
- options accessor object
-