Class ConfigurationContext
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.module.context.ConfigurationContext
-
public final class ConfigurationContext extends java.lang.Object
Configuration context used internally to track all registered configuration items. Items may be registered by type (installer, extension) or by instance (module, bundle).Each item is registered only once, but all registrations are tracked. Uniqueness guaranteed by type.
Support generic disabling mechanism (for items marked with
DisableSupport
sign). If item is disabled, but never registered special empty item info will be created at the end of configuration.Considered as internal api.
- Since:
- 06.07.2016
- See Also:
for details of tracked info
,for acessing collected info at runtime
-
-
Constructor Summary
Constructors Constructor Description ConfigurationContext()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bundleStarted()
Called after complete guice bundle startup (other dropwizard bundle's run phase (for bundles registered after guice bundle) may not yet be called).void
closeScope()
Clears current scope.void
disableBundle(java.lang.Class<? extends GuiceyBundle>[] bundles)
Guicey bundle manual disable registration fromGuiceBundle.Builder.disableBundles(Class[])
.void
disableDropwizardBundle(java.lang.Class<? extends io.dropwizard.core.ConfiguredBundle>[] bundles)
Guicey bundle manual disable registration fromGuiceBundle.Builder.disableBundles(Class[])
.void
disableExtensions(java.lang.Class<?>[] extensions)
Extension manual disable registration fromGuiceBundle.Builder.disableExtensions(Class[])
.void
disableInstallers(java.lang.Class<? extends FeatureInstaller>[] installers)
Installer manual disable registration fromGuiceBundle.Builder.disableInstallers(Class[])
orGuiceyBootstrap.disableInstallers(Class[])
.void
disableModules(java.lang.Class<? extends com.google.inject.Module>[] modules)
Guice module manual disable registration fromGuiceBundle.Builder.disableModules(Class[])
.void
finalizeConfiguration()
Called when context configuration is finished (but extensions installation is not finished yet).io.dropwizard.core.setup.Bootstrap
getBootstrap()
io.dropwizard.core.setup.Bootstrap
getBootstrapProxy()
Proxy object created on first access because of ~200ms creation overhead.io.dropwizard.core.Configuration
getConfiguration()
ConfigurationTree
getConfigurationTree()
java.util.List<GuiceyBundle>
getDisabledBundles()
Note: before configuration finalization this returns all actually disabled bundles and after finalization all disables (including never registered bundles).java.util.List<io.dropwizard.core.ConfiguredBundle>
getDisabledDropwizardBundles()
java.util.List<java.lang.Class<?>>
getDisabledExtensions()
Note: before configuration finalization this returns all actually disabled extensions and after finalization all disables (including never registered extensions).java.util.List<java.lang.Class<? extends FeatureInstaller>>
getDisabledInstallers()
Note: before configuration finalization this returns all actually disabled installers and after finalization all disables (including never registered installers).java.util.List<com.google.inject.Module>
getDisabledModules()
Note: before configuration finalization this returns all actually disabled modules and after finalization all disables (including never registered modules).java.util.List<java.lang.Class<java.lang.Object>>
getDisabledModuleTypes()
java.util.List<GuiceyBundle>
getEnabledBundles()
java.util.List<io.dropwizard.core.ConfiguredBundle>
getEnabledDropwizardBundles()
java.util.List<java.lang.Class<?>>
getEnabledExtensions()
java.util.List<java.lang.Class<? extends FeatureInstaller>>
getEnabledInstallers()
java.util.List<com.google.inject.Module>
getEnabledModules()
NOTE: both normal and overriding modules.io.dropwizard.core.setup.Environment
getEnvironment()
ExtensionsHolder
getExtensionsHolder()
<T> java.util.List<T>
getIgnoredItems(ConfigItem type)
<T extends ItemInfoImpl>
TgetInfo(java.lang.Object item)
<T> java.util.List<T>
getItems(ConfigItem type)
<T> java.util.List<T>
getItems(ConfigItem type, java.util.function.Predicate<T> filter)
java.util.List<com.google.inject.Module>
getNormalModules()
ExtensionItemInfoImpl
getOrRegisterBindingExtension(java.lang.Class<?> extension, java.lang.Class<? extends com.google.inject.Module> topScope)
Registration of extension detected from guice binding.ExtensionItemInfoImpl
getOrRegisterExtension(java.lang.Class<?> extension, boolean fromScan)
Extensions classpath scan requires testing with all installers to recognize actual extensions.java.util.List<com.google.inject.Module>
getOverridingModules()
SharedConfigurationState
getSharedState()
void
initPhaseStarted(io.dropwizard.core.setup.Bootstrap bootstrap)
void
installersResolved(java.util.List<FeatureInstaller> installers)
Called with prepared list of installers to use for extensions recognition and installation.boolean
isBundleEnabled(ItemId id)
Bundle must be disabled before it's processing, otherwise disabling will not have effect (because bundle will be already processed and register all related items).boolean
isExtensionEnabled(java.lang.Class<?> extension)
LifecycleSupport
lifecycle()
void
openScope(ItemId scope)
Current configuration context (application, bundle or classpath scan).<V,T extends java.lang.Enum & Option>
Voption(T option)
OptionsSupport
options()
java.util.List<GuiceyBundle>
registerBundles(GuiceyBundle... bundles)
Usual bundle registration fromGuiceBundle.Builder.bundles(GuiceyBundle...)
orGuiceyBootstrap.bundles(GuiceyBundle...)
.void
registerCommands(java.util.List<java.lang.Class<io.dropwizard.core.cli.Command>> commands)
Register commands resolved with classpath scan.void
registerDisablePredicates(java.util.function.Predicate<ItemInfo>[] predicates)
Register disable predicates, used to disable all matched items.void
registerDropwizardBundles(io.dropwizard.core.ConfiguredBundle... bundles)
Direct dropwizard bundle registration fromGuiceBundle.Builder.dropwizardBundles(ConfiguredBundle...)
orGuiceyBootstrap.dropwizardBundles( ConfiguredBundle[])
.void
registerExtensions(java.lang.Class<?>... extensions)
Usual extension registration fromGuiceBundle.Builder.extensions(Class[])
orGuiceyBootstrap.extensions(Class[])
.void
registerExtensionsOptional(java.lang.Class<?>... extensions)
Optional extension registration fromGuiceBundle.Builder.extensionsOptional(Class[])
orGuiceyBootstrap.extensionsOptional(Class[])
.void
registerInstallers(java.lang.Class<? extends FeatureInstaller>[] installers)
Usual installer registration fromGuiceBundle.Builder.installers(Class[])
orGuiceyBootstrap.installers(Class[])
.void
registerInstallersFromScan(java.util.List<java.lang.Class<? extends FeatureInstaller>> installers)
Register installers from classpath scan.void
registerLookupBundles(java.util.List<GuiceyBundle> bundles)
Register bundles resolved by lookup mechanism.void
registerModules(com.google.inject.Module... modules)
void
registerModulesOverride(com.google.inject.Module... modules)
ItemId
replaceContextScope(ItemId scope)
Declares possibly sub-configuration context.void
runHooks(GuiceBundle.Builder builder)
Runs all registered hooks (at the end of manual builder configuration) and fire success event.void
runPhaseStarted(io.dropwizard.core.Configuration configuration, io.dropwizard.core.setup.Environment environment)
void
setDuplicatesDetector(DuplicateConfigDetector detector)
Change default duplicates detector.<T extends java.lang.Enum & Option>
voidsetOption(T option, java.lang.Object value)
StatsTracker
stat()
-
-
-
Method Detail
-
setDuplicatesDetector
public void setDuplicatesDetector(DuplicateConfigDetector detector)
Change default duplicates detector.- Parameters:
detector
- new policy
-
openScope
public void openScope(ItemId scope)
Current configuration context (application, bundle or classpath scan).- Parameters:
scope
- scope key
-
replaceContextScope
public ItemId replaceContextScope(ItemId scope)
Declares possibly sub-configuration context. For example, to track dropwizard bundles initialization scope.- Parameters:
scope
- scope key- Returns:
- previous scope or null (for application scope)
-
closeScope
public void closeScope()
Clears current scope.
-
registerCommands
public void registerCommands(java.util.List<java.lang.Class<io.dropwizard.core.cli.Command>> commands)
Register commands resolved with classpath scan.- Parameters:
commands
- installed commands- See Also:
GuiceBundle.Builder.searchCommands()
-
registerLookupBundles
public void registerLookupBundles(java.util.List<GuiceyBundle> bundles)
Register bundles resolved by lookup mechanism.GuiceyBundleLookup
used as context.- Parameters:
bundles
- bundles resolved by lookup mechanism- See Also:
GuiceyBundleLookup
-
registerBundles
public java.util.List<GuiceyBundle> registerBundles(GuiceyBundle... bundles)
Usual bundle registration fromGuiceBundle.Builder.bundles(GuiceyBundle...)
orGuiceyBootstrap.bundles(GuiceyBundle...)
. Context class is set to currently processed bundle.- Parameters:
bundles
- bundles to register- Returns:
- list of actually registered bundles (without duplicates)
-
disableBundle
public void disableBundle(java.lang.Class<? extends GuiceyBundle>[] bundles)
Guicey bundle manual disable registration fromGuiceBundle.Builder.disableBundles(Class[])
.- Parameters:
bundles
- modules to disable
-
getEnabledBundles
public java.util.List<GuiceyBundle> getEnabledBundles()
- Returns:
- all configured bundles (without duplicates)
-
getDisabledBundles
public java.util.List<GuiceyBundle> getDisabledBundles()
Note: before configuration finalization this returns all actually disabled bundles and after finalization all disables (including never registered bundles).- Returns:
- all configured disabled bundles (without duplicates)
-
isBundleEnabled
public boolean isBundleEnabled(ItemId id)
Bundle must be disabled before it's processing, otherwise disabling will not have effect (because bundle will be already processed and register all related items).- Parameters:
id
- bundle id- Returns:
- true if bundle enabled, false otherwise
-
registerDropwizardBundles
public void registerDropwizardBundles(io.dropwizard.core.ConfiguredBundle... bundles)
Direct dropwizard bundle registration fromGuiceBundle.Builder.dropwizardBundles(ConfiguredBundle...)
orGuiceyBootstrap.dropwizardBundles( ConfiguredBundle[])
. Context class is set to currently processed bundle.- Parameters:
bundles
- dropwizard bundles
-
disableDropwizardBundle
public void disableDropwizardBundle(java.lang.Class<? extends io.dropwizard.core.ConfiguredBundle>[] bundles)
Guicey bundle manual disable registration fromGuiceBundle.Builder.disableBundles(Class[])
.- Parameters:
bundles
- modules to disable
-
getEnabledDropwizardBundles
public java.util.List<io.dropwizard.core.ConfiguredBundle> getEnabledDropwizardBundles()
- Returns:
- all configured dropwizard bundles (without duplicates)
-
getDisabledDropwizardBundles
public java.util.List<io.dropwizard.core.ConfiguredBundle> getDisabledDropwizardBundles()
- Returns:
- all disabled dropwizard bundles
-
getBootstrapProxy
public io.dropwizard.core.setup.Bootstrap getBootstrapProxy()
Proxy object created on first access because of ~200ms creation overhead.- Returns:
- bootstrap proxy object
-
registerModules
public void registerModules(com.google.inject.Module... modules)
- Parameters:
modules
- guice modules to register
-
registerModulesOverride
public void registerModulesOverride(com.google.inject.Module... modules)
- Parameters:
modules
- overriding guice modules to register
-
disableModules
public void disableModules(java.lang.Class<? extends com.google.inject.Module>[] modules)
Guice module manual disable registration fromGuiceBundle.Builder.disableModules(Class[])
.- Parameters:
modules
- modules to disable
-
getEnabledModules
public java.util.List<com.google.inject.Module> getEnabledModules()
NOTE: both normal and overriding modules.- Returns:
- all configured and enabled guice modules (without duplicates)
-
getNormalModules
public java.util.List<com.google.inject.Module> getNormalModules()
- Returns:
- list of all enabled normal guice modules or empty list
-
getOverridingModules
public java.util.List<com.google.inject.Module> getOverridingModules()
- Returns:
- list of all enabled overriding modules or empty list
-
getDisabledModules
public java.util.List<com.google.inject.Module> getDisabledModules()
Note: before configuration finalization this returns all actually disabled modules and after finalization all disables (including never registered modules).- Returns:
- list of disabled modules or empty list
-
getDisabledModuleTypes
public java.util.List<java.lang.Class<java.lang.Object>> getDisabledModuleTypes()
- Returns:
- all disabled module types, including never registered
-
registerInstallers
public void registerInstallers(java.lang.Class<? extends FeatureInstaller>[] installers)
Usual installer registration fromGuiceBundle.Builder.installers(Class[])
orGuiceyBootstrap.installers(Class[])
.- Parameters:
installers
- installers to register
-
registerInstallersFromScan
public void registerInstallersFromScan(java.util.List<java.lang.Class<? extends FeatureInstaller>> installers)
Register installers from classpath scan. UseClasspathScanner
as context class.- Parameters:
installers
- installers found by classpath scan
-
disableInstallers
public void disableInstallers(java.lang.Class<? extends FeatureInstaller>[] installers)
Installer manual disable registration fromGuiceBundle.Builder.disableInstallers(Class[])
orGuiceyBootstrap.disableInstallers(Class[])
.- Parameters:
installers
- installers to disable
-
getEnabledInstallers
public java.util.List<java.lang.Class<? extends FeatureInstaller>> getEnabledInstallers()
- Returns:
- all configured and enabled installers (including resolved by scan)
-
getDisabledInstallers
public java.util.List<java.lang.Class<? extends FeatureInstaller>> getDisabledInstallers()
Note: before configuration finalization this returns all actually disabled installers and after finalization all disables (including never registered installers).- Returns:
- list of disabled installers
-
installersResolved
public void installersResolved(java.util.List<FeatureInstaller> installers)
Called with prepared list of installers to use for extensions recognition and installation.- Parameters:
installers
- installers to use in correct order
-
getExtensionsHolder
public ExtensionsHolder getExtensionsHolder()
- Returns:
- extensions holder object
-
registerExtensions
public void registerExtensions(java.lang.Class<?>... extensions)
Usual extension registration fromGuiceBundle.Builder.extensions(Class[])
orGuiceyBootstrap.extensions(Class[])
.- Parameters:
extensions
- extensions to register
-
registerExtensionsOptional
public void registerExtensionsOptional(java.lang.Class<?>... extensions)
Optional extension registration fromGuiceBundle.Builder.extensionsOptional(Class[])
orGuiceyBootstrap.extensionsOptional(Class[])
.- Parameters:
extensions
- optional extensions to register
-
getOrRegisterExtension
public ExtensionItemInfoImpl getOrRegisterExtension(java.lang.Class<?> extension, boolean fromScan)
Extensions classpath scan requires testing with all installers to recognize actual extensions. To avoid duplicate installers recognition, extensions resolved by classpath scan are registered immediately. It's required because of not obvious method used for both manually registered extensions (to obtain container) and to create container from extensions from classpath scan.- Parameters:
extension
- found extensionfromScan
- true when called for extension found in classpath scan, false for manually registered extension- Returns:
- extension info container
-
getOrRegisterBindingExtension
public ExtensionItemInfoImpl getOrRegisterBindingExtension(java.lang.Class<?> extension, java.lang.Class<? extends com.google.inject.Module> topScope)
Registration of extension detected from guice binding. Descriptor for extension may already exists.Top guice module must be used because it's the only module, known by guicey configuration model and so the only way to show it properly on configuration report. Guice report can show extensions in correct positions, if required.
- Parameters:
extension
- extension classtopScope
- top module in registration modules hierarchy- Returns:
- extension info container
-
disableExtensions
public void disableExtensions(java.lang.Class<?>[] extensions)
Extension manual disable registration fromGuiceBundle.Builder.disableExtensions(Class[])
.- Parameters:
extensions
- extensions to disable
-
isExtensionEnabled
public boolean isExtensionEnabled(java.lang.Class<?> extension)
- Parameters:
extension
- extension type- Returns:
- true if extension is enabled, false if disabled
-
getEnabledExtensions
public java.util.List<java.lang.Class<?>> getEnabledExtensions()
- Returns:
- all configured extensions (including resolved by scan)
-
getDisabledExtensions
public java.util.List<java.lang.Class<?>> getDisabledExtensions()
Note: before configuration finalization this returns all actually disabled extensions and after finalization all disables (including never registered extensions).- Returns:
- list of disabled extensions
-
setOption
public <T extends java.lang.Enum & Option> void setOption(T option, java.lang.Object value)
- Type Parameters:
T
- helper type to define option- Parameters:
option
- option enumvalue
- option value (not null)
-
option
public <V,T extends java.lang.Enum & Option> V option(T option)
- Type Parameters:
V
- value typeT
- helper type to define option- Parameters:
option
- option enum- Returns:
- option value (set or default)
-
options
public OptionsSupport options()
- Returns:
- options support object
-
registerDisablePredicates
public void registerDisablePredicates(java.util.function.Predicate<ItemInfo>[] predicates)
Register disable predicates, used to disable all matched items.After registration predicates are applied to all currently registered items to avoid registration order influence.
- Parameters:
predicates
- disable predicates
-
runHooks
public void runHooks(GuiceBundle.Builder builder)
Runs all registered hooks (at the end of manual builder configuration) and fire success event.- Parameters:
builder
- bundle builder
-
initPhaseStarted
public void initPhaseStarted(io.dropwizard.core.setup.Bootstrap bootstrap)
- Parameters:
bootstrap
- dropwizard bootstrap instance
-
runPhaseStarted
public void runPhaseStarted(io.dropwizard.core.Configuration configuration, io.dropwizard.core.setup.Environment environment)
- Parameters:
configuration
- dropwizard configuration instanceenvironment
- dropwizard environment instance
-
finalizeConfiguration
public void finalizeConfiguration()
Called when context configuration is finished (but extensions installation is not finished yet). Merges disabled items configuration with registered items or creates new items to hold disable info.
-
bundleStarted
public void bundleStarted()
Called after complete guice bundle startup (other dropwizard bundle's run phase (for bundles registered after guice bundle) may not yet be called).
-
getItems
public <T> java.util.List<T> getItems(ConfigItem type)
- Type Parameters:
T
- expected items type- Parameters:
type
- config type- Returns:
- list of all registered items of type or empty list
-
getItems
public <T> java.util.List<T> getItems(ConfigItem type, java.util.function.Predicate<T> filter)
- Type Parameters:
T
- expected items type- Parameters:
type
- config typefilter
- items filter- Returns:
- list of all items matching filter or empty list
-
getIgnoredItems
public <T> java.util.List<T> getIgnoredItems(ConfigItem type)
- Type Parameters:
T
- expected items type- Parameters:
type
- config type- Returns:
- list of all detected duplicates of this configuration type
-
getInfo
public <T extends ItemInfoImpl> T getInfo(java.lang.Object item)
- Type Parameters:
T
- expected container type- Parameters:
item
- item to get info- Returns:
- item registration info container or null if item not registered
-
stat
public StatsTracker stat()
- Returns:
- startup statistics tracker instance
-
lifecycle
public LifecycleSupport lifecycle()
- Returns:
- lifecycle events broadcaster
-
getBootstrap
public io.dropwizard.core.setup.Bootstrap getBootstrap()
- Returns:
- dropwizard bootstrap object
-
getConfiguration
public io.dropwizard.core.Configuration getConfiguration()
- Returns:
- dropwizard configuration object
-
getConfigurationTree
public ConfigurationTree getConfigurationTree()
- Returns:
- introspected configuration object
-
getEnvironment
public io.dropwizard.core.setup.Environment getEnvironment()
- Returns:
- dropwizard environment object
-
getSharedState
public SharedConfigurationState getSharedState()
- Returns:
- application-wide registry object
-
-